Skip to content
Snippets Groups Projects
Unverified Commit c0327e8d authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3418136 by shalini_jha, smustgrave, rohit sankhla: Add last() function...

Issue #3418136 by shalini_jha, smustgrave, rohit sankhla: Add last() function to ItemInterface/ItemList

(cherry picked from commit b7ce2ab9)
parent ae6dff1e
No related branches found
No related tags found
23 merge requests!11887Issue #3520065: The migrate Row class API is incomplete,!11636Draft: Issue #3515643 by macsim: fieldNameExists method is inconsistent,!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator,!10570Issue #3494197: Convert Twig engine hooks,!10567Issue #3494154: Index is not added if entity doesn't support revisions,!10548Revert "Issue #3478621 by catch, longwave, nicxvan: Add filecache to OOP hook attribute parsing",!10404Margin has been added,!10391Issue #3485117 by nexusnovaz, godotislate, nicxvan: Fix return type on...,!10388Issue #3485117 by nexusnovaz, godotislate, nicxvan: Fix return type on...,!10376Issue #3485117 by nexusnovaz, godotislate, nicxvan: Fix return type on...
Pipeline #347044 passed with warnings
Pipeline: drupal

#347052

    ...@@ -91,6 +91,14 @@ public function set($index, $value); ...@@ -91,6 +91,14 @@ public function set($index, $value);
    */ */
    public function first(); public function first();
    /**
    * Returns the last item in this list.
    *
    * @return \Drupal\Core\TypedData\TypedDataInterface|null
    * The last item in this list, or NULL if there are no items.
    */
    public function last(): ?TypedDataInterface;
    /** /**
    * Appends a new item to the list. * Appends a new item to the list.
    * *
    ......
    ...@@ -303,4 +303,11 @@ public function __clone() { ...@@ -303,4 +303,11 @@ public function __clone() {
    } }
    } }
    /**
    * {@inheritdoc}
    */
    public function last(): ?TypedDataInterface {
    return $this->get($this->count() - 1);
    }
    } }
    ...@@ -695,4 +695,25 @@ public function testTypedDataValidation(): void { ...@@ -695,4 +695,25 @@ public function testTypedDataValidation(): void {
    $this->assertSame('0.value', $violations[0]->getPropertyPath()); $this->assertSame('0.value', $violations[0]->getPropertyPath());
    } }
    /**
    * Tests the last() method on typed data lists.
    */
    public function testTypedDataListsLast(): void {
    // Create an ItemList with two string items.
    $value = ['zero', 'one'];
    $typed_data = $this->createTypedData(ListDataDefinition::create('string'), $value);
    // Assert that the last item is the second one ('one').
    $this->assertEquals('one', $typed_data->last()->getValue());
    // Add another item to the list and check the last item.
    $value[] = 'two';
    $typed_data = $this->createTypedData(ListDataDefinition::create('string'), $value);
    $this->assertEquals('two', $typed_data->last()->getValue());
    // Check behavior with an empty list.
    $typed_data = $this->createTypedData(ListDataDefinition::create('string'), []);
    $this->assertNull($typed_data->last(), 'Empty list should return NULL.');
    }
    } }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment