You are here

class ContentModerationIPEAccess in Lightning Workflow 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/IPEAccess/ContentModerationIPEAccess.php \Drupal\lightning_workflow\Plugin\IPEAccess\ContentModerationIPEAccess
  2. 8.2 src/Plugin/IPEAccess/ContentModerationIPEAccess.php \Drupal\lightning_workflow\Plugin\IPEAccess\ContentModerationIPEAccess

Provides Panels IPE access logic for Content Moderation integration.

@internal This is an internal part of Lightning Workflow's integration with Panels and may be changed or removed at any time. External code should not use or extend this class in any way!

Plugin annotation


@IPEAccess(
  id = "content_moderation_ipe",
  label = @Translation("Content moderation")
)

Hierarchy

Expanded class hierarchy of ContentModerationIPEAccess

File

src/Plugin/IPEAccess/ContentModerationIPEAccess.php, line 26

Namespace

Drupal\lightning_workflow\Plugin\IPEAccess
View source
class ContentModerationIPEAccess extends IPEAccessBase implements ContainerFactoryPluginInterface {

  /**
   * The moderation information service.
   *
   * @var \Drupal\content_moderation\ModerationInformationInterface
   */
  protected $information;

  /**
   * ContentModerationIPEAccess constructor.
   *
   * @param array $configuration
   *   An array of plugin configuration options.
   * @param string $plugin_id
   *   The plugin ID.
   * @param mixed $plugin_definition
   *   The plugin definition.
   * @param \Drupal\content_moderation\ModerationInformationInterface $information
   *   The moderation information service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ModerationInformationInterface $information) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->information = $information;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('content_moderation.moderation_information'));
  }

  /**
   * {@inheritdoc}
   */
  public function applies(PanelsDisplayVariant $display) {
    $contexts = $display
      ->getContexts();
    if (empty($contexts['@panelizer.entity_context:entity'])) {
      return FALSE;
    }
    $context = $contexts['@panelizer.entity_context:entity'];
    if ($context
      ->hasContextValue()) {
      return $this->information
        ->isModeratedEntity($context
        ->getContextValue());
    }
    else {
      return FALSE;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function access(PanelsDisplayVariant $display) {
    $entity = $display
      ->getContexts()['@panelizer.entity_context:entity']
      ->getContextValue();
    return $this
      ->isLatestRevision($entity) && !$this->information
      ->isLiveRevision($entity);
  }

  /**
   * Determines if an entity is the latest revision.
   *
   * This is a shim around RevisionableInterface::isLatestRevision() and
   * ModerationInformationInterface::isLatestRevision(). The former is added in
   * Drupal 8.8, deprecating the latter.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity to check.
   *
   * @return bool
   *   TRUE if the entity is the latest revision, FALSE otherwise.
   */
  private function isLatestRevision(EntityInterface $entity) {
    return $entity instanceof RevisionableInterface && method_exists($entity, 'isLatestRevision') ? $entity
      ->isLatestRevision() : call_user_func([
      $this->information,
      'isLatestRevision',
    ], $entity);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentModerationIPEAccess::$information protected property The moderation information service.
ContentModerationIPEAccess::access public function
ContentModerationIPEAccess::applies public function
ContentModerationIPEAccess::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ContentModerationIPEAccess::isLatestRevision private function Determines if an entity is the latest revision.
ContentModerationIPEAccess::__construct public function ContentModerationIPEAccess constructor.