Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AddModeration.php

function AddModeration::apply

Overrides ConfigActionPluginInterface::apply

File

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

Class

AddModeration

Namespace

Drupal\content_moderation\Plugin\ConfigAction

Code

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();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal