Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityOperations.php

function EntityOperations::isPublished

Checks if the entity is published.

This method is optimized to not have to unnecessarily load the moderation state and workflow if it is not required.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to check.

Return value

bool TRUE if the entity is published, FALSE otherwise.

1 call to EntityOperations::isPublished()
EntityOperations::entityView in core/modules/content_moderation/src/EntityOperations.php
Act on entities being assembled before rendering.

File

core/modules/content_moderation/src/EntityOperations.php, line 311

Class

EntityOperations
Defines a class for reacting to entity events.

Namespace

Drupal\content_moderation

Code

protected function isPublished(ContentEntityInterface $entity) {
    // If the entity implements EntityPublishedInterface directly, check that
    // first, otherwise fall back to check through the workflow state.
    if ($entity instanceof EntityPublishedInterface) {
        return $entity->isPublished();
    }
    if ($moderation_state = $entity->get('moderation_state')->value) {
        $workflow = $this->moderationInfo
            ->getWorkflowForEntity($entity);
        return $workflow->getTypePlugin()
            ->getState($moderation_state)
            ->isPublishedState();
    }
    return FALSE;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal