class AddModerationDeriver

Same name in other branches
  1. 11.x core/modules/content_moderation/src/Plugin/ConfigAction/AddModerationDeriver.php \Drupal\content_moderation\Plugin\ConfigAction\AddModerationDeriver

Hierarchy

Expanded class hierarchy of AddModerationDeriver

File

core/modules/content_moderation/src/Plugin/ConfigAction/AddModerationDeriver.php, line 17

Namespace

Drupal\content_moderation\Plugin\ConfigAction
View source
final class AddModerationDeriver extends DeriverBase implements ContainerDeriverInterface {
    use StringTranslationTrait;
    public function __construct(EntityTypeManagerInterface $entityTypeManager) {
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, $base_plugin_id) : static {
        return new static($container->get(EntityTypeManagerInterface::class));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinitions($base_plugin_definition) {
        $inflector = new EnglishInflector();
        foreach ($this->entityTypeManager
            ->getDefinitions() as $id => $entity_type) {
            if ($bundle_entity_type = $entity_type->getBundleEntityType()) {
                
                /** @var \Drupal\Core\Entity\EntityTypeInterface $bundle_entity_type */
                $bundle_entity_type = $this->entityTypeManager
                    ->getDefinition($bundle_entity_type);
                // Convert unique plugin IDs, like `taxonomy_vocabulary`, into strings
                // like `TaxonomyVocabulary`.
                $suffix = Container::camelize($bundle_entity_type->id());
                [
                    $suffix,
                ] = $inflector->pluralize($suffix);
                $this->derivatives["add{$suffix}"] = [
                    'target_entity_type' => $id,
                    'admin_label' => $this->t('Add moderation to all @bundles', [
                        '@bundles' => $bundle_entity_type->getPluralLabel() ?: $bundle_entity_type->id(),
                    ]),
                ] + $base_plugin_definition;
            }
        }
        return parent::getDerivativeDefinitions($base_plugin_definition);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AddModerationDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
AddModerationDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
AddModerationDeriver::__construct public function
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. 3
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.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.