diff --git a/src/Plugin/Condition/NodeIsPublished.php b/src/Plugin/Condition/NodeIsPublished.php new file mode 100644 index 00000000..a378aaa4 --- /dev/null +++ b/src/Plugin/Condition/NodeIsPublished.php @@ -0,0 +1,94 @@ +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.'); + } + } + +}