function ContentModerationHooks::entityBundleFieldInfo

Implements hook_entity_bundle_field_info().

Attributes

#[Hook('entity_bundle_field_info')]

File

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

Class

ContentModerationHooks
Hook implementations for content_moderation.

Namespace

Drupal\content_moderation\Hook

Code

public function entityBundleFieldInfo(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) : array {
  if (isset($base_field_definitions['moderation_state'])) {
    // Add the target bundle to the moderation state field. Since each bundle
    // can be attached to a different moderation workflow, adding this
    // information to the field definition allows the associated workflow to
    // be derived where a field definition is present.
    $base_field_definitions['moderation_state']->setTargetBundle($bundle);
    return [
      'moderation_state' => $base_field_definitions['moderation_state'],
    ];
  }
  return [];
}

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