isPublishedState example

return $result;
  }

  /** * {@inheritdoc} */
  public function isLiveRevision(ContentEntityInterface $entity) {
    $workflow = $this->getWorkflowForEntity($entity);
    return $entity->isLatestRevision()
      && $entity->isDefaultRevision()
      && $entity->moderation_state->value
      && $workflow->getTypePlugin()->getState($entity->moderation_state->value)->isPublishedState();
  }

  /** * {@inheritdoc} */
  public function isDefaultRevisionPublished(ContentEntityInterface $entity) {
    $workflow = $this->getWorkflowForEntity($entity);
    $default_revision = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->load($entity->id());
    // If no default revision could be loaded, the entity has not yet been     // saved. In this case the moderation_state of the unsaved entity can be     // used, since once saved it will become the default.

  public function buildConfigurationForm(array $form, FormStateInterface $form_state, StateInterface $state = NULL) {
    /** @var \Drupal\content_moderation\ContentModerationState $state */
    $state = $form_state->get('state');
    $is_required_state = isset($state) ? in_array($state->id()$this->workflowType->getRequiredStates(), TRUE) : FALSE;

    $form = [];
    $form['published'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Published'),
      '#description' => $this->t('When content reaches this state it should be published.'),
      '#default_value' => isset($state) ? $state->isPublishedState() : FALSE,
      '#disabled' => $is_required_state,
    ];

    $form['default_revision'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Default revision'),
      '#description' => $this->t('When content reaches this state it should be made the default revision; this is implied for published states.'),
      '#default_value' => isset($state) ? $state->isDefaultRevisionState() : FALSE,
      '#disabled' => $is_required_state,
      // @todo Add form #state to force "make default" on when "published" is       // on for a state.
->getState($entity->moderation_state->value);

      // This entity is default if it is new, the default revision, or the       // default revision is not published.       $update_default_revision = $entity->isNew()
        || $current_state->isDefaultRevisionState()
        || !$this->moderationInfo->isDefaultRevisionPublished($entity);

      // Fire per-entity-type logic for handling the save process.       $this->entityTypeManager
        ->getHandler($entity->getEntityTypeId(), 'moderation')
        ->onPresave($entity$update_default_revision$current_state->isPublishedState());
    }
  }

  /** * @param \Drupal\Core\Entity\EntityInterface $entity * The entity that was just saved. * * @see hook_entity_insert() */
  public function entityInsert(EntityInterface $entity) {
    if ($this->moderationInfo->isModeratedEntity($entity)) {
      
// This entity is default if it is new, the default revision state, or the       // default revision is not published.       if (!$entity->isSyncing()) {
        $update_default_revision = $entity->isNew()
          || $current_state->isDefaultRevisionState()
          || !$content_moderation_info->isDefaultRevisionPublished($entity);

        $entity->isDefaultRevision($update_default_revision);
      }

      // Update publishing status if it can be updated and if it needs updating.       $published_state = $current_state->isPublishedState();
      if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
        $published_state ? $entity->setPublished() : $entity->setUnpublished();
      }
    }
  }

  /** * {@inheritdoc} */
  public function generateSampleItems($count = 1) {
    // No sample items generated since the starting moderation state is always
Home | Imprint | This part of the site doesn't use cookies.