function ContentModerationHooks::entityBundleInfoAlter

Implements hook_entity_bundle_info_alter().

Attributes

#[Hook('entity_bundle_info_alter')]

File

core/modules/content_moderation/src/Hook/ContentModerationHooks.php, line 294

Class

ContentModerationHooks
Hook implementations for content_moderation.

Namespace

Drupal\content_moderation\Hook

Code

public function entityBundleInfoAlter(&$bundles) : void {
  $translatable = FALSE;
  /** @var \Drupal\workflows\WorkflowInterface $workflow */
  foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
    /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */
    $plugin = $workflow->getTypePlugin();
    foreach ($plugin->getEntityTypes() as $entity_type_id) {
      foreach ($plugin->getBundlesForEntityType($entity_type_id) as $bundle_id) {
        if (isset($bundles[$entity_type_id][$bundle_id])) {
          $bundles[$entity_type_id][$bundle_id]['workflow'] = $workflow->id();
          // If we have even one moderation-enabled translatable bundle, we
          // need to make the moderation state bundle translatable as well, to
          // enable the revision translation merge logic also for content
          // moderation state revisions.
          if (!empty($bundles[$entity_type_id][$bundle_id]['translatable'])) {
            $translatable = TRUE;
          }
        }
      }
    }
  }
  $bundles['content_moderation_state']['content_moderation_state']['translatable'] = $translatable;
}

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