function AddModeration::apply

Same name in other branches
  1. 11.x core/modules/content_moderation/src/Plugin/ConfigAction/AddModeration.php \Drupal\content_moderation\Plugin\ConfigAction\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();
}

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