You are here

class FieldGroupLocalAction in Field Group 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/Derivative/FieldGroupLocalAction.php \Drupal\field_group\Plugin\Derivative\FieldGroupLocalAction

Provides local action definitions for all entity bundles.

Hierarchy

Expanded class hierarchy of FieldGroupLocalAction

1 string reference to 'FieldGroupLocalAction'
field_group.links.action.yml in ./field_group.links.action.yml
field_group.links.action.yml

File

src/Plugin/Derivative/FieldGroupLocalAction.php, line 15

Namespace

Drupal\field_group\Plugin\Derivative
View source
class FieldGroupLocalAction 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;

  /**
   * Constructs a FieldUiLocalAction 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.
   */
  public function __construct(RouteProviderInterface $route_provider, EntityTypeManagerInterface $entity_type_manager) {
    $this->routeProvider = $route_provider;
    $this->entityTypeManager = $entity_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'));
  }

  /**
   * {@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')) {
        $default_options = [
          'title' => $this
            ->t('Add field group'),
        ];
        $this->derivatives['field_group_add_' . $entity_type_id . '_form_display'] = [
          'route_name' => "field_ui.field_group_add_{$entity_type_id}.form_display",
          'appears_on' => [
            "entity.entity_form_display.{$entity_type_id}.default",
          ],
        ] + $default_options;
        $this->derivatives['field_group_add_' . $entity_type_id . '_form_display_form_mode'] = [
          'route_name' => "field_ui.field_group_add_{$entity_type_id}.form_display.form_mode",
          'appears_on' => [
            "entity.entity_form_display.{$entity_type_id}.form_mode",
          ],
        ] + $default_options;
        $this->derivatives['field_group_add_' . $entity_type_id . '_display'] = [
          'route_name' => "field_ui.field_group_add_{$entity_type_id}.display",
          'appears_on' => [
            "entity.entity_view_display.{$entity_type_id}.default",
          ],
        ] + $default_options;
        $this->derivatives['field_group_add_' . $entity_type_id . '_display_view_mode'] = [
          'route_name' => "field_ui.field_group_add_{$entity_type_id}.display.view_mode",
          'appears_on' => [
            "entity.entity_view_display.{$entity_type_id}.view_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
FieldGroupLocalAction::$entityTypeManager protected property The entity type manager.
FieldGroupLocalAction::$routeProvider protected property The route provider.
FieldGroupLocalAction::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
FieldGroupLocalAction::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
FieldGroupLocalAction::__construct public function Constructs a FieldUiLocalAction 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.