hook_flag_alter() is no longer needed on D8.

Core provides https://api.drupal.org/api/drupal/core!modules!system!entity.api.php/fun..., hence hook_flag_load().

Remaining tasks

- remove the documentation for this hook from the api.php file
- write a change record that explains the change. This should be aimed at module developers, and give before and after examples of a hook implementation

CommentFileSizeAuthor
#3 2461669-3.patch571 bytesPalashvijay4O
#1 2461669-1.patch458 bytesPalashvijay4O

Comments

Palashvijay4O’s picture

Status: Active » Needs review
StatusFileSize
new458 bytes

Uploading a patch.

Status: Needs review » Needs work

The last submitted patch, 1: 2461669-1.patch, failed testing.

Palashvijay4O’s picture

Status: Needs work » Needs review
StatusFileSize
new571 bytes

Sorry created a patch against wrong branch. Here's the right one. Please review. Thanks !

joachim’s picture

Thanks for working on this. Patch looks perfect.

Do you also want to have a go at creating a draft change record?

Palashvijay4O’s picture

Yeah sure I can give a try!!

joachim’s picture

Great! Paste the link here when you want me to take a look at it.

Palashvijay4O’s picture

https://www.drupal.org/node/2462383
This is a draft .. Please let me know is that enough or need to add more things.

joachim’s picture

Status: Needs review » Needs work

It looks like you've copied the table row from the issue about all the hooks. That's not quite the right approach here. We need something that explains what the hook was used for, and what you're meant to do now. Both should give code examples.

I've had a quick search of core CRs, looking for the word 'removed'. Here's one that's the same sort of thing, though it covers 2 hooks: https://www.drupal.org/node/2420295

Palashvijay4O’s picture

I am kind of stuck on this.. Can you tell me something more.. not able to find how this was implemented in D7

joachim’s picture

Sure :)

We need to give an example of using this hook. Ideally, we want something realistic. We could make something up -- eg, change the text of one of the flag's labels.

Or perhaps we can find a real implementation. Flag doesn't implement its own hook (sometimes modules do, but generally not). If I google for 'implements hook_flag_alter', I get two results that are implementations:

- http://cgit.drupalcode.org/commons_follow/tree/commons_follow.module?id=...
- http://totemdrupal.com/docs/html/a00014.html

...and they both look like crack to me. Altering the subtypes the flag applies to seems crazy to me. But heyho. It's a use case, apparently.

Let's forget about all the logic these implementations do though. That's overkill. So all we really want is something like:

function mymodule_flag_alter(yadayada) {
  $flag->types[] = 'foo';
}

Of course I don't recall offhand the structure of $flag->types, so that bit could be nonsense... :)

Palashvijay4O’s picture

Thanks! After doing little research I am able to get what's going on here. Let me summarize to you once if I am thinking right. Since drupal_alter is moved to bootstrap.inc so this will be loaded on every Drupal request therefore so request to every module extending hook_flag_alter will be made. So there is now need to hook_flag_alter explicitly...
Please let me know if what I get is right?

joachim’s picture

I think you're on the wrong track with chasing drupal_alter()...

Here's a rough overview:

On D7, hook_flag_alter() was invoked whenever a flag configuration object was loaded. This allowed other modules to change properties of flags from their stored settings. For example, a module could dynamically change the entity bundles a flag applied to, or the flag's UI labels.

On D8, a flag is a configuration entity. Drupal core invokes hook_entity_load() and hook_ENTITY_TYPE_load() on all entities of all types when they are loaded. Either of these hooks can be used to accomplish the same things as hook_flag_alter() on D7. (Though obviously we recommend using hook_ENTITY_TYPE_load() in our example.)

Is that clearer?

Palashvijay4O’s picture

@joachim its clearer but I am not so good at documenting. I would like you or someone else to publish the change record so that I can learn some more things.
Thank you for the support!!

joachim’s picture

No problem.

Looks like you actually made 2 CRs. I've marked one as a duplicate, and written up the other one: https://www.drupal.org/node/2462383.

joachim’s picture

Status: Needs work » Fixed

Patch was good, so committed it.

Thanks for working on this!

  • joachim committed f1a987e on 8.x-4.x authored by Palashvijay4O
    Issue #2461669 by Palashvijay4O: Removed hook_flag_alter() documentation...

Status: Fixed » Closed (fixed)

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