You are here

class JuiceboxConfFieldContextualLinks in Juicebox HTML5 Responsive Image Galleries 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/JuiceboxConfFieldContextualLinks.php \Drupal\juicebox\Plugin\Derivative\JuiceboxConfFieldContextualLinks

Provides dynamic contextual links for Juicebox field conf editing.

Hierarchy

Expanded class hierarchy of JuiceboxConfFieldContextualLinks

1 string reference to 'JuiceboxConfFieldContextualLinks'
juicebox.links.contextual.yml in ./juicebox.links.contextual.yml
juicebox.links.contextual.yml

File

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

Namespace

Drupal\juicebox\Plugin\Derivative
View source
class JuiceboxConfFieldContextualLinks extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

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

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   A string translation service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
    $this->entityTypeManager = $entity_type_manager;
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {

    // Create a new instance of the deriver. This also allows us to extract
    // services from the container and inject them into our deriver via its own
    // constructor as needed.
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('string_translation'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    // We need a contextual link defined for each entity type (that may contain
    // a Juicebox gallery) in order to provide a link to the relevant edit
    // display screen. These link definitions must be unique because the related
    // route to the edit display screen is different for each entity type.
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {

      // Only fieldable entity are candidates.
      if ($entity_type
        ->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
        $bundle_entity_type = $entity_type
          ->getBundleEntityType();
        $this->derivatives['juicebox.conf_field_' . $entity_type_id]['title'] = $this
          ->t('Configure galleries of this field instance');
        $this->derivatives['juicebox.conf_field_' . $entity_type_id]['route_name'] = 'entity.entity_view_display.' . $entity_type_id . '.view_mode';
        $this->derivatives['juicebox.conf_field_' . $entity_type_id]['group'] = 'juicebox_conf_field_' . $entity_type_id;
      }
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

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
JuiceboxConfFieldContextualLinks::$entityTypeManager protected property A Drupal entity type manager service.
JuiceboxConfFieldContextualLinks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
JuiceboxConfFieldContextualLinks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
JuiceboxConfFieldContextualLinks::__construct public function Constructor.
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.