You are here

public function EntityFlagActionDeriver::getDerivativeDefinitions in Flag 8.4

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Derivative/EntityFlagActionDeriver.php, line 45

Class

EntityFlagActionDeriver
Generate flag/unflag action plugins for each flag.

Namespace

Drupal\flag\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  foreach ($this->flagService
    ->getAllFlags() as $flag_id => $flag) {
    foreach ([
      'flag',
      'unflag',
    ] as $action) {
      $this->derivatives[$flag_id . '_' . $action] = [
        'id' => $flag_id . '_' . $action,
        'label' => $flag
          ->getShortText($action),
        'type' => $flag
          ->getFlaggableEntityTypeId(),
      ] + $base_plugin_definition;
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}