You are here

class DynamicAddEntityLocalActions in Apigee Edge 8

Add add entity local actions for Apigee Edge entity's collection routes.

Hierarchy

Expanded class hierarchy of DynamicAddEntityLocalActions

1 string reference to 'DynamicAddEntityLocalActions'
apigee_edge.links.action.yml in ./apigee_edge.links.action.yml
apigee_edge.links.action.yml

File

src/Plugin/Derivative/DynamicAddEntityLocalActions.php, line 34

Namespace

Drupal\apigee_edge\Plugin\Derivative
View source
class DynamicAddEntityLocalActions extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The base plugin ID.
   *
   * @var string
   */
  protected $basePluginId;

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

  /**
   * The moderation information service.
   *
   * @var \Drupal\content_moderation\ModerationInformationInterface
   */
  protected $moderationInfo;

  /**
   * Creates an DynamicAddEntityLocalTasks object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The translation manager.
   */
  public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
    $this->entityTypeManager = $entity_type_manager;
    $this->stringTranslation = $string_translation;
    $this->basePluginId = $base_plugin_id;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $type) {
      if ($type instanceof EdgeEntityTypeInterface) {
        foreach ($this->entityTypeManager
          ->getRouteProviders($type
          ->id()) as $provider) {
          $collection_route_name = "entity.{$type->id()}.collection";
          $collection_route = $provider
            ->getRoutes($type)
            ->get($collection_route_name);
          $add_form_route_name = "entity.{$type->id()}.add_form";
          $add_form_route = $provider
            ->getRoutes($type)
            ->get($add_form_route_name);
          if ($collection_route && $add_form_route) {
            $this->derivatives["{$type->getProvider()}.{$type->id()}.add_form"] = [
              'route_name' => $add_form_route_name,
              'title' => $this
                ->t('Add @entity-type', [
                '@entity-type' => mb_strtolower($type
                  ->getSingularLabel()),
              ]),
              'appears_on' => [
                $collection_route_name,
              ],
            ] + $base_plugin_definition;
            break;
          }
        }
      }
    }
    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
DynamicAddEntityLocalActions::$basePluginId protected property The base plugin ID.
DynamicAddEntityLocalActions::$entityTypeManager protected property The entity type manager.
DynamicAddEntityLocalActions::$moderationInfo protected property The moderation information service.
DynamicAddEntityLocalActions::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DynamicAddEntityLocalActions::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
DynamicAddEntityLocalActions::__construct public function Creates an DynamicAddEntityLocalTasks 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.