You are here

class FormComponentAddLocalAction in Flexiform 8

Provides local action definitions for all entity bundles.

Hierarchy

Expanded class hierarchy of FormComponentAddLocalAction

1 string reference to 'FormComponentAddLocalAction'
flexiform.links.action.yml in ./flexiform.links.action.yml
flexiform.links.action.yml

File

src/Plugin/Deriver/FormComponentAddLocalAction.php, line 17

Namespace

Drupal\flexiform\Plugin\Deriver
View source
class FormComponentAddLocalAction extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The route provider.
   *
   * @var \Drupal\Core\Routing\RouteProviderInterface
   */
  protected $routeProvider;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The form component type plugin manager.
   *
   * @var \Drupal\flexiform\FormComponentTypePluginManager
   */
  protected $formComponentTypeManager;

  /**
   * Constructs a FormComponentAddLocationAction object.
   *
   * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
   *   The route provider to load routes by name.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\flexiform\FormComponentTypePluginManager $form_component_type_manager
   *   The form component type plugin manager.
   */
  public function __construct(RouteProviderInterface $route_provider, EntityTypeManagerInterface $entity_type_manager, FormComponentTypePluginManager $form_component_type_manager) {
    $this->routeProvider = $route_provider;
    $this->entityTypeManager = $entity_type_manager;
    $this->formComponentTypeManager = $form_component_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('router.route_provider'), $container
      ->get('entity_type.manager'), $container
      ->get('plugin.manager.flexiform.form_component_type'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
FormComponentAddLocalAction::$entityTypeManager protected property The entity type manager.
FormComponentAddLocalAction::$formComponentTypeManager protected property The form component type plugin manager.
FormComponentAddLocalAction::$routeProvider protected property The route provider.
FormComponentAddLocalAction::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
FormComponentAddLocalAction::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
FormComponentAddLocalAction::__construct public function Constructs a FormComponentAddLocationAction object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.