class AddModeration

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

Hierarchy

Expanded class hierarchy of AddModeration

File

core/modules/content_moderation/src/Plugin/ConfigAction/AddModeration.php, line 15

Namespace

Drupal\content_moderation\Plugin\ConfigAction
View source
final class AddModeration implements ConfigActionPluginInterface, ContainerFactoryPluginInterface {
    public function __construct(ConfigManagerInterface $configManager, EntityTypeManagerInterface $entityTypeManager, string $pluginId, string $targetEntityType) {
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : static {
        assert(is_array($plugin_definition));
        $target_entity_type = $plugin_definition['target_entity_type'];
        return new static($container->get(ConfigManagerInterface::class), $container->get(EntityTypeManagerInterface::class), $plugin_id, $target_entity_type);
    }
    
    /**
     * {@inheritdoc}
     */
    public function apply(string $configName, mixed $value) : void {
        $workflow = $this->configManager
            ->loadConfigEntityByName($configName);
        assert($workflow instanceof WorkflowInterface);
        $plugin = $workflow->getTypePlugin();
        if (!$plugin instanceof ContentModerationInterface) {
            throw new ConfigActionException("The {$this->pluginId} config action only works with Content Moderation workflows.");
        }
        assert($value === '*' || is_array($value));
        if ($value === '*') {
            
            /** @var \Drupal\Core\Entity\EntityTypeInterface $definition */
            $definition = $this->entityTypeManager
                ->getDefinition($this->targetEntityType);
            
            /** @var string $bundle_entity_type */
            $bundle_entity_type = $definition->getBundleEntityType();
            $value = $this->entityTypeManager
                ->getStorage($bundle_entity_type)
                ->getQuery()
                ->accessCheck(FALSE)
                ->execute();
        }
        foreach ($value as $bundle) {
            $plugin->addEntityTypeAndBundle($this->targetEntityType, $bundle);
        }
        $workflow->save();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AddModeration::apply public function Applies the config action. Overrides ConfigActionPluginInterface::apply
AddModeration::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
AddModeration::__construct public function

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