Currently fields can be aggregated by the following types:

  • Fulltext
  • Sum
  • Count
  • Maximum
  • Minimum
  • First
  • First Letter
  • List

It would be great if it were possible to aggregate by "Last" as well.

As explained by drunken monkey, it would be possible by patching the module in the following way:

No, but it should be simple to add this yourself – either by directly modifying the existing data alteration or by copying the code to create a new, custom one.

I figured I'd add this as a feature request, in case someone with module coding knowledge also has interest in this feature. Thanks in advanced for the feature request consideration!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NWOM created an issue. See original summary.

drunken monkey’s picture

Thanks for creating the issue!
I'm not sure how many people could use this feature, but it's a pretty small change, so if someone provided a patch I'd review and commit it.

JorgenSandstrom’s picture

Try this patch. It works for me. I set data type to "text" in stead of string so the result can be used as well for output.

drunken monkey’s picture

Component: General code » Plugins
Status: Active » Needs work

Thanks for the patch – however, the request was for "Last", not "Last letter".
Otherwise, looks good, though. Do you need this type on your site? It seems even more of a niche feature than "Last", but same argument: it's a very small addition, so should be fine.
I would stay with string as type, though, to be consistent – the user can change the type themselves in any case.

NWOM’s picture

Title: Aggregation Type - Last » Aggregation Type - Last & Last Letter
Status: Needs work » Needs review

Here is a patch that includes Last and the aforementioned Last Letter aggregation types. Please review.

NWOM’s picture

drunken monkey’s picture

Great job, thanks!
Would be nice if someone could test this and verify it works correctly, but otherwise I guess I'd still commit it.

However, again the question – does anyone actually want "Last letter"? Otherwise, I'd really leave that out, it doesn't seem useful for even those few lines of code (plus the UI clutter, which weighs more heavily). Also, it's a bit strange, I think, that it takes the last letter from the first value, not the last – but that's debatable.

NWOM’s picture

Yeah, I can't see a use case for it either to be honest. @JorgenSandstrom what is your use case for Last Letter of the first value?

JorgenSandstrom’s picture

I'm sorry. I misunderstood the issue description. I came across this while working on a custom aggregation type and thought I'd help. I do not have a use case for last letter.

NWOM’s picture

Oh, well thank you anyways for the help. It definitely helped me create the patch (since I wasn't sure how to create one myself). When I have more time, I will re-add the patch with just the aggregation type "Last" then.

drunken monkey’s picture

Ah, OK, thanks a lot for clearing that up, everyone!
Then here is the patch with just "Last". Please give it another try and I can commit it.

NWOM’s picture

Ah thanks for this. Was wrapped up in a few features for a project the last few weeks, that I forgot to come back to this issue. Will test it out tomorrow and mark as RTBC.

Status: Needs review » Needs work

The last submitted patch, 11: 2765317-11--last_aggregation.patch, failed testing.

drunken monkey’s picture

Status: Needs work » Needs review
NWOM’s picture

Title: Aggregation Type - Last & Last Letter » Aggregation Type - Last
Status: Needs review » Reviewed & tested by the community

It works great! Sorry again for the delay. Appreciate you adding this to the module. I hope it helps others that are looking for the same feature.

drunken monkey’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Novice

No problem, thanks for reporting back!
Committed.
Thanks again, everyone!

Needs to be ported to D8 still. (As does the "First letter" aggregation, now that I look at it.)

vasike’s picture

Status: Patch (to be ported) » Needs review
FileSize
3.36 KB

let's try a patch

drunken monkey’s picture

Status: Needs review » Needs work

Thanks a lot for the patch, looks pretty good already!
However, why do you need to remove the one assertion for the "Last" type? I don't see a reason why it shouldn't apply – you just need to pass the right expected values.
Also, I'd remove "simply" from the description – I can see you just copied the description from "First", which of course makes sense, but if they're too similar it kinda looks weird, reading them one after the other.

vasike’s picture

Status: Needs work » Needs review
Issue tags: +DevDaysSeville
FileSize
2.3 KB
2.52 KB

here is an updated patch (and its diff) for the requested changes (#19)

  • drunken monkey committed 771986d on 8.x-1.x authored by vasike
    Issue #2765317 by vasike: Added a "Last" aggregation for aggregated...
drunken monkey’s picture

Status: Needs review » Fixed

Looks great now, thanks!
Committed.

Status: Fixed » Closed (fixed)

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