Problem/Motivation

As a module developer that wants to take advantage of flag module and implement my own logic of some updates based on flagged/unflagged content, I'd like to subscribe to both events at the same time, and I have no problems with that, but every time one will subscribe to both events, they will have to handle events differently in their code, as the API is inconsistent, FlaggingEvent works with one flagging, while UnflaggingEvent works with an array of flaggings.

Proposed resolution

Drupal core content entities use foreach to iterate over entities in postDelete and send hook_entity_delete separately for every one, I'm wondering if it would be better for DX to do the same for UnflaggingEvent.

Remaining tasks

Provide a patch

User interface changes

None

API changes

UnflaggingEvent constructor accepts array of flaggings entities, after the change it should accept one flagging.

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

asgorobets created an issue. See original summary.

asgorobets’s picture

I'm happy to provide a patch if that's a valid issue

joachim’s picture

That does seem like a confusing inconsistency!

Let's see what @socketwench says about this. Also, should be tagged as beta blocker but I'm not sure offhand what our tag for that is.

socketwench’s picture

So the problem is that as it stands, UnflaggingEvent is more versatile as it isn't tied to a particular flag. We only pass the flaggings. We don't use it internally in any other way, however, so we narrow the definition of UnflaggingEvent.

There's also a problem with how the event class is initialized. In Flagging::preDelete(), we're given a list of entities to delete. As a result, we have to either check all flaggings passed to the static method, or assume they're all from the same flag.

Status: Needs review » Needs work

The last submitted patch, 4: unflaggingEvent_2755683.4.patch, failed testing.

The last submitted patch, 4: unflaggingEvent_2755683.4.patch, failed testing.

joachim’s picture

Issue tags: +beta blocker

Patch has whitespace issues, and also doesn't seem to be addressing the subject of this issue?

rbayliss’s picture

Yeah, it looks like the preDelete hook can get called for a bunch of flaggings at once. For the sake of consistency, how about something like this instead?

Berdir’s picture

We did this on purpose, as a performance improvement. unflag could happen on hundreds of flaggings at once, especially when removing them all to delete a flag.

And flag currently has no concept of multiple, so not sure it makes sense to make that multiple.

I don't really see a problem with them being different.

socketwench’s picture

Status: Needs review » Needs work
FileSize
1.93 KB

Just a reroll for the whitespace issues.

neclimdul’s picture

And flag currently has no concept of multiple, so not sure it makes sense to make that multiple.

"One is a special case of many."

Building the concept of many into the flag API would do a couple improvements IMHO.
1) Make things consistent, solving this issue and preserves the performance improvement.
2) Leave the API open for bulk operations in the future.

Seems like a better option if this is going to happen. If not I'd say this is just won't fix after 3 years of silence and people using the alpha releases.