- $component = $display->getComponent('content_moderation_control');
- if ($component) {
- $build['content_moderation_control'] = $this->formBuilder->getForm(EntityModerationForm::class, $entity);
+ $build['content_moderation_control'] = $this->formBuilder->getForm(EntityModerationForm::class, $entity);
+ }
+
+ /**
+ * 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.
+ *
+ * @param \Drupal\Core\Entity\ContentEntityInterface $entity
+ * The entity to check.
+ *
+ * @return bool
+ * TRUE if the entity is published, FALSE otherwise.
+ */
+ 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();