New Action to compare lists

Created on 26 November 2024, 5 months ago

Problem/Motivation

It would be helpful to have an Action that can compare two (simple) lists. Main use case is determining which values in a list field are being changed (during a pre-save event).

Proposed resolution

Custom list_compare action that will accept two (similar) lists as input ("primary" and "secondary") and return a token containing items determined by a selectable array function.

For example, a new array of

  1. elements that are present in the primary array, but not in the secondary array (when using array_diff)
  2. an array of only the elements that are present in both (using array_intersect)

Remaining tasks

Possibly add additional array functions, such as

  • array_diff_assoc
  • array_diff_key
  • array_intersect_assoc
  • array_intersect_key

Add ability for the secondary array input to accept either a comma-separated list or multiple arrays at once.

Strengthen the ability to compare deeper multi-dimensional arrays (user roles, composite webform fields, etc).

Add non-comparison functions that operate on multiple similar lists, as well? As a separate module?

  • array_combine
  • array_merge
✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States glottus

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @glottus
  • πŸ‡ΊπŸ‡ΈUnited States glottus
  • πŸ‡ΊπŸ‡ΈUnited States glottus

    This patch adds the described functionality but needs code review and testing.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Please turn this into an issue fork with an MR, patches are no longer used. That's not only because tests will be run on MRs, which is always the first step to get all tests green before anyone should review new code.

  • Merge request !457Add action to compare lists β†’ (Merged) created by Unnamed author
  • πŸ‡ΊπŸ‡ΈUnited States glottus

    Done - thanks for the advice and patience. First time getting through the MR process on drupalcode.

  • Pipeline finished with Failed
    5 months ago
    Total: 457s
    #358130
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    @glottus thanks for going through this, I hope it is a somewhat fun experience. It looks great so far.

    Just a couple of issues with the tests. Would be great if you could fix them and get the tests to green again. After that, you could set the issue status to "Needs review", then we can have a look and merge this asap.

  • Pipeline finished with Failed
    5 months ago
    Total: 458s
    #359553
  • Pipeline finished with Failed
    5 months ago
    Total: 464s
    #359574
  • Pipeline finished with Failed
    5 months ago
    Total: 516s
    #359585
  • Pipeline finished with Failed
    5 months ago
    Total: 292s
    #359589
  • Pipeline finished with Canceled
    5 months ago
    Total: 76s
    #359590
  • Pipeline finished with Failed
    5 months ago
    Total: 482s
    #359591
  • Pipeline finished with Canceled
    5 months ago
    Total: 85s
    #359598
  • Pipeline finished with Failed
    5 months ago
    Total: 178s
    #359599
  • Pipeline finished with Success
    5 months ago
    Total: 462s
    #359607
  • πŸ‡ΊπŸ‡ΈUnited States glottus

    Yikes. Sorry for all the cruft above. Fumbling my way through!

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    This is great work, thank you so much @glottus

    Yikes. Sorry for all the cruft above. Fumbling my way through!

    No worries at all, you're doing great.

    I've left a few remarks in the MR. Nothing big, just some clean-up and wording items. Some of it are just questions, please feel free to decline suggestions in there.

  • πŸ‡ΊπŸ‡ΈUnited States glottus

    Thanks for your remarks - I'm hoping to get back to this within the week, but having trouble getting set up or understanding how/where I can see your comments in context. Keep getting "make sure you have the correct access rights and the repository exists" errors, despite generating and adding the necessary keys and being able to edit through the website. Will need some more time to fix that before I can work more efficiently, but to answer a couple questions:
    1) I had it in the Content submodule because I wasn't having luck (yet) comparing anything other than simple arrays, which I expected (and my use case was specifically) from simple text (list) fields in entities, but as it grows, you're right, I could see it being useful elsewhere.
    2) I don't have strong feelings about "first/second" vs "primary/secondary", and could very easily be more encumbered by being a native English speaker! Your perspective is appreciated, and I agree, "first" and "second" could be more easily understood by all. I was trying to imply a little more than just numbering, but rather that the "primary" array would be the one on the left side of the array_function - the one to be compared to others - if you want to know what's in one array but not another, it's like a "left join" where some importance is communicated by the first one being "more important", so I called that "primary".
    3) Yes, this was all copied/pasted from a different iteration in which some of the language was project-specific. I'll make some adjustments when I can see your comments in context a little better.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    how/where I can see your comments in context

    When you're logged in, both on d.o and on GitLab, you can click on the MR above and you'll see all the comments within the code diff. Direct link to that is https://git.drupalcode.org/project/eca/-/merge_requests/457

    As for 1), you'll find more list related actions in the eca_base submodule as well, that's why I thought it should belong there.

    As for 2), this is not a requirement, I leave that totally up to your decision.

  • Pipeline finished with Canceled
    5 months ago
    Total: 211s
    #366061
  • Pipeline finished with Failed
    5 months ago
    Total: 802s
    #366062
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Is this ready for another review? Status still says "Needs work".

  • πŸ‡ΊπŸ‡ΈUnited States glottus
  • Pipeline finished with Failed
    4 months ago
    Total: 557s
    #395296
  • Pipeline finished with Canceled
    4 months ago
    Total: 558s
    #395297
  • Pipeline finished with Failed
    4 months ago
    Total: 571s
    #395298
  • Pipeline finished with Failed
    4 months ago
    Total: 584s
    #395295
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    This looks great, I've only cleaned up the code in 2 areas:

    • Removed named arguments as we're not using them elsewhere either.
    • Merged the 2 traits into the action plugin class, as those traits are not re-used elsewhere and are so small, that having them in separate files feels more overhead than benefit.

    Thanks a lot @glottus for this contribution and congrats, your first MR went really well.

  • Pipeline finished with Success
    4 months ago
    Total: 507s
    #395303
  • Pipeline finished with Skipped
    4 months ago
    #395306
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Test are green, merged.

  • Status changed to Fixed 3 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Skipped
    3 months ago
    #414787
  • Pipeline finished with Success
    3 months ago
    Total: 337s
    #416906
Production build 0.71.5 2024