isDefaultRevisionPublished example

if ($entity->moderation_state->value) {
      $workflow = $this->moderationInfo->getWorkflowForEntity($entity);
      /** @var \Drupal\content_moderation\ContentModerationState $current_state */
      $current_state = $workflow->getTypePlugin()
        ->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() */
// Change the entity's default revision flag and the publishing status only     // if the new workflow state is a valid one.     if ($workflow && $workflow->getTypePlugin()->hasState($moderation_state_id)) {
      /** @var \Drupal\content_moderation\ContentModerationState $current_state */
      $current_state = $workflow->getTypePlugin()->getState($moderation_state_id);

      // 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();
      }
    }
  }

  


  /** * @covers ::isDefaultRevisionPublished * @dataProvider isDefaultRevisionPublishedTestCases */
  public function testIsDefaultRevisionPublished($initial_state$final_state$initial_is_default_published$final_is_default_published) {
    $entity = EntityTestMulRevPub::create([
      'moderation_state' => $initial_state,
    ]);
    $entity->save();
    $this->assertEquals($initial_is_default_published$this->moderationInformation->isDefaultRevisionPublished($entity));

    $entity->moderation_state = $final_state;
    $entity->save();
    $this->assertEquals($final_is_default_published$this->moderationInformation->isDefaultRevisionPublished($entity));
  }

  /** * Test cases for ::testIsDefaultRevisionPublished. */
  public function isDefaultRevisionPublishedTestCases() {
    return [
      
Home | Imprint | This part of the site doesn't use cookies.