You are here

class MandrillActivityLocalTasks in Mandrill 8

Defines dynamic local tasks for Mandrill Activity.

Hierarchy

Expanded class hierarchy of MandrillActivityLocalTasks

1 string reference to 'MandrillActivityLocalTasks'
mandrill_activity.links.task.yml in modules/mandrill_activity/mandrill_activity.links.task.yml
modules/mandrill_activity/mandrill_activity.links.task.yml

File

modules/mandrill_activity/src/Plugin/Derivative/MandrillActivityLocalTasks.php, line 19
Contains \Drupal\mandrill_activity\Plugin\Derivative\MandrillActivityLocalTasks.

Namespace

Drupal\mandrill_activity\Plugin\Derivative
View source
class MandrillActivityLocalTasks extends DeriverBase implements ContainerDeriverInterface {

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

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $activity_ids = \Drupal::entityQuery('mandrill_activity')
      ->execute();
    $entity_definitions = $this->entityTypeManager
      ->getDefinitions();
    $activity_entities = MandrillActivity::loadMultiple($activity_ids);

    /* @var $activity \Drupal\mandrill_activity\Entity\MandrillActivity */
    foreach ($activity_entities as $activity) {
      $entity = $entity_definitions[$activity->entity_type];
      if (!$activity->enabled || empty($entity)) {
        continue;
      }

      // Determine if the entity has a canonical path to add this task to.
      $link_templates = $entity
        ->getLinkTemplates();
      $has_canonical_path = isset($link_templates['canonical']);
      $task = $activity->entity_type . '.mandrill_activity';
      $this->derivatives[$task] = $base_plugin_definition;
      $this->derivatives[$task]['title'] = 'Mandrill Activity';
      $this->derivatives[$task]['route_name'] = 'entity.' . $activity->entity_type . '.mandrill_activity';
      $this->derivatives[$task]['base_route'] = 'entity.' . $activity->entity_type . ($has_canonical_path ? '.canonical' : '.edit_form');
    }
    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
MandrillActivityLocalTasks::$entityTypeManager protected property The entity type manager.
MandrillActivityLocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
MandrillActivityLocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
MandrillActivityLocalTasks::__construct public function Constructor.