Browse Source

Node Is Published Condition (#151)

* Create NodeIsPublished.php

* fix partial commit

* phpcbf

* fix constructors
pull/729/head
Seth Shaw 5 years ago committed by Mark Jordan
parent
commit
f6252999ae
  1. 94
      src/Plugin/Condition/NodeIsPublished.php

94
src/Plugin/Condition/NodeIsPublished.php

@ -0,0 +1,94 @@
<?php
namespace Drupal\islandora\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides an 'Is Published' condition for nodes.
*
* @Condition(
* id = "node_is_published",
* label = @Translation("Node is published"),
* context = {
* "node" = @ContextDefinition("entity:node", required = TRUE , label = @Translation("node"))
* }
* )
*/
class NodeIsPublished extends ConditionPluginBase implements ContainerFactoryPluginInterface {
/**
* Term storage.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* Constructor.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
* Entity type manager.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
EntityTypeManager $entity_type_manager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function evaluate() {
$node = $this->getContextValue('node');
if (!$node && !$this->isNegated()) {
return FALSE;
}
if ($node->isPublished() && !$this->isNegated()) {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function summary() {
if (!empty($this->configuration['negate'])) {
return $this->t('The node is not published.');
}
else {
return $this->t('The node is published.');
}
}
}
Loading…
Cancel
Save