Problem/Motivation

There is a first() method in Drupal/Core/TypedData/Plugin/DataType/ItemList.php but no last(), which seem to be a pretty standard and easy method to implement.

Proposed resolution

Something like:

public function last() {
  return $this->get($this->count() - 1);
}

Remaining tasks

  • Add new method
  • Write Test coverage
  • Write Documentation
  • Write Release note

Issue fork drupal-3418136

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

NicklasMF created an issue. See original summary.

Rohit Sankhla made their first commit to this issue’s fork.

rohit sankhla’s picture

Status: Active » Needs review

Added last method in Drupal/Core/TypedData/Plugin/DataType/ItemList.php, Please review.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs change record

Will need simple test coverage

Change record

And should have a return typehint

shalini_jha made their first commit to this issue’s fork.

shalini_jha’s picture

I have added return value for last method same as first method.

shalini_jha’s picture

Status: Needs work » Needs review

I have added the Test coverage and Change record for this. The change record is currently in draft. Moving this for NR, kindly review.

smustgrave’s picture

Status: Needs review » Needs work
shalini_jha’s picture

Assigned: Unassigned » shalini_jha
shalini_jha’s picture

Assigned: shalini_jha » Unassigned
Status: Needs work » Needs review

Moving this to NR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests, -Needs change record +Needs Review Queue Initiative

Fixed return syntax. Rest appears good and feedback addressed.

alexpott’s picture

Version: 11.x-dev » 11.1.x-dev
Status: Reviewed & tested by the community » Fixed

I searched contrib and there doesn't appear to be any clashing functions and this helps to make the interface more fluent and natural so +1

Committed and pushed b7ce2ab918e to 11.x and c0327e8d90c to 11.1.x. Thanks!

  • alexpott committed c0327e8d on 11.1.x
    Issue #3418136 by shalini_jha, smustgrave, rohit sankhla: Add last()...

  • alexpott committed b7ce2ab9 on 11.x
    Issue #3418136 by shalini_jha, smustgrave, rohit sankhla: Add last()...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.