Change record status: 
Project: 
Introduced in branch: 
8.x-4.x
Description: 

Prior to 8.x-4.x, 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 8.x-4.x, 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.

7.x

/**
 * Implements hook_flag_alter().
 */
function mymodule_flag_alter($flag) {
  // Allow the 'foobar' flag to apply to article nodes.
  if ($flag->name == 'foobar') {
    $flag->types[] = 'article';
  }
}

8.x

/**
 * Implements hook_ENTITY_TYPE_load() for flag.
 */
function mymodule_flag_load($entities) {
  foreach ($entities as $flag) {
    // Allow the 'foobar' flag to apply to article nodes.
    if ($flag->id() == 'foobar') {
      // NB. This example is possibly bogus as this property is possibly protected!
      $flag->types[] = 'article';
    }
  }
}
Impacts: 
Module developers