You are here

class DynamicLocalTasks in CiviCRM Entity 8.3

Generates moderation-related local tasks.

Hierarchy

Expanded class hierarchy of DynamicLocalTasks

1 string reference to 'DynamicLocalTasks'
civicrm_entity.links.task.yml in ./civicrm_entity.links.task.yml
civicrm_entity.links.task.yml

File

src/Plugin/Derivative/DynamicLocalTasks.php, line 16

Namespace

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

  /**
   * Creates an FieldUiLocalTask 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 = [];
    $civicrm_entities = array_filter($this->entityTypeManager
      ->getDefinitions(), function (EntityTypeInterface $type) {
      return $type
        ->getProvider() == 'civicrm_entity' && $type
        ->get('civicrm_entity_ui_exposed');
    });
    foreach ($civicrm_entities as $entity_type_id => $entity_type) {
      $this->derivatives["{$entity_type_id}.canonical"] = [
        'route_name' => "entity.{$entity_type_id}.canonical",
        'title' => $this
          ->t('View'),
        'base_route' => "entity.{$entity_type_id}.canonical",
      ] + $base_plugin_definition;
      $this->derivatives["{$entity_type_id}.edit_form"] = [
        'route_name' => "entity.{$entity_type_id}.edit_form",
        'title' => $this
          ->t('Edit'),
        'base_route' => "entity.{$entity_type_id}.canonical",
      ] + $base_plugin_definition;
      $this->derivatives["entity.{$entity_type_id}.collection"] = [
        'route_name' => "entity.{$entity_type_id}.collection",
        'title' => $this
          ->t('List'),
        'base_route' => "entity.{$entity_type_id}.collection",
        'weight' => -10,
      ] + $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
DynamicLocalTasks::$basePluginId protected property The base plugin ID.
DynamicLocalTasks::$entityTypeManager protected property The entity type manager.
DynamicLocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DynamicLocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
DynamicLocalTasks::__construct public function Creates an FieldUiLocalTask 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.