You are here

public function FormComponentAddLocalAction::getDerivativeDefinitions in Flexiform 8

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/Deriver/FormComponentAddLocalAction.php, line 71

Class

FormComponentAddLocalAction
Provides local action definitions for all entity bundles.

Namespace

Drupal\flexiform\Plugin\Deriver

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if ($entity_type
      ->get('field_ui_base_route')) {
      foreach ($this->formComponentTypeManager
        ->getDefinitions() as $plugin_id => $definition) {
        $component_type = $this->formComponentTypeManager
          ->createInstance($plugin_id);
        if (!$component_type instanceof FormComponentTypeCreateableInterface) {
          continue;
        }
        $default_options = [
          'title' => $this
            ->t('Add @label', [
            '@label' => $definition['label'],
          ]),
        ];
        $this->derivatives["entity.entity_form_display.{$entity_type_id}.default.component_type.{$plugin_id}.add"] = [
          'route_name' => "entity.entity_form_display.{$entity_type_id}.default.component_type.{$plugin_id}.add",
          'appears_on' => [
            "entity.entity_form_display.{$entity_type_id}.default",
          ],
        ] + $default_options;
        $this->derivatives["entity.entity_form_display.{$entity_type_id}.form_mode.component_type.{$plugin_id}.add"] = [
          'route_name' => "entity.entity_form_display.{$entity_type_id}.form_mode.component_type.{$plugin_id}.add",
          'appears_on' => [
            "entity.entity_form_display.{$entity_type_id}.form_mode",
          ],
        ] + $default_options;
      }
    }
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}