You are here

public function EntityPresaveDeriver::getDerivativeDefinitions in Rules 8.3

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/RulesEvent/EntityPresaveDeriver.php, line 52

Class

EntityPresaveDeriver
Derives entity presave plugin definitions based on content entity types.

Namespace

Drupal\rules\Plugin\RulesEvent

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {

    // Only allow content entities and ignore configuration entities.
    if (!$entity_type instanceof ContentEntityTypeInterface) {
      continue;
    }
    $this->derivatives[$entity_type_id] = [
      'label' => $this
        ->t('Before saving a @entity_type', [
        '@entity_type' => $entity_type
          ->getSingularLabel(),
      ]),
      'category' => $entity_type
        ->getLabel(),
      'entity_type_id' => $entity_type_id,
      'context_definitions' => [
        $entity_type_id => [
          'type' => "entity:{$entity_type_id}",
          'label' => $entity_type
            ->getLabel(),
        ],
        $entity_type_id . '_unchanged' => [
          'type' => "entity:{$entity_type_id}",
          'label' => $this
            ->t('Unchanged @entity_type', [
            '@entity_type' => $entity_type
              ->getLabel(),
          ]),
        ],
      ],
    ] + $base_plugin_definition;
  }
  return $this->derivatives;
}