You are here

class CivicrmEntityMenuLink in CiviCRM Entity 8.3

Provides local action definitions for all CiviCRM entity definitions.

Hierarchy

Expanded class hierarchy of CivicrmEntityMenuLink

1 string reference to 'CivicrmEntityMenuLink'
civicrm_entity.links.menu.yml in ./civicrm_entity.links.menu.yml
civicrm_entity.links.menu.yml

File

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

Namespace

Drupal\civicrm_entity\Plugin\Derivative
View source
class CivicrmEntityMenuLink extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

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

  /**
   * Constructs a CivicrmEntityLocalAction object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityTypeManager = $entity_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) {
    $this->derivatives = [];
    $civicrm_entities = array_filter($this->entityTypeManager
      ->getDefinitions(), function (EntityTypeInterface $type) {
      return $type
        ->getProvider() == 'civicrm_entity' && $type
        ->get('civicrm_entity_ui_exposed');
    });

    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    foreach ($civicrm_entities as $entity_type_id => $entity_type) {
      $this->derivatives["field_storage_config_add_{$entity_type_id}"] = [
        'route_name' => "entity.{$entity_type_id}.collection",
        'title' => $entity_type
          ->getLabel(),
        'parent' => 'civicrm_entity.admin',
        'description' => $this
          ->t('Manage :label', [
          ':label' => $entity_type
            ->getLabel(),
        ]),
      ] + $base_plugin_definition;
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CivicrmEntityMenuLink::$entityTypeManager protected property The entity type manager.
CivicrmEntityMenuLink::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
CivicrmEntityMenuLink::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
CivicrmEntityMenuLink::__construct public function Constructs a CivicrmEntityLocalAction object.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
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.