loadContentModerationStateRevision example

protected function getModerationStateId() {
    $entity = $this->getEntity();

    /** @var \Drupal\content_moderation\ModerationInformationInterface $moderation_info */
    $moderation_info = \Drupal::service('content_moderation.moderation_information');
    if (!$moderation_info->shouldModerateEntitiesOfBundle($entity->getEntityType()$entity->bundle())) {
      return NULL;
    }

    // Existing entities will have a corresponding content_moderation_state     // entity associated with them.     if (!$entity->isNew() && $content_moderation_state = $this->loadContentModerationStateRevision($entity)) {
      return $content_moderation_state->moderation_state->value;
    }

    // It is possible that the bundle does not exist at this point. For example,     // the node type form creates a fake Node entity to get default values.     // @see \Drupal\node\NodeTypeForm::form()     $workflow = $moderation_info->getWorkFlowForEntity($entity);
    return $workflow ? $workflow->getTypePlugin()->getInitialState($entity)->id() : NULL;
  }

  /** * Load the content moderation state revision associated with an entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity the content moderation state entity will be loaded from. * * @return \Drupal\content_moderation\Entity\ContentModerationStateInterface|null * The content_moderation_state revision or FALSE if none exists. */
Home | Imprint | This part of the site doesn't use cookies.