From 0c8337421630f290d671cbd96728a913a073e367 Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Fri, 6 Dec 2024 16:24:18 -0400 Subject: [PATCH] New condition plugins for media and terms published. --- src/Plugin/Condition/MediaIsPublished.php | 96 +++++++++++++++++++ .../Condition/TaxonomyTermIsPublished.php | 96 +++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 src/Plugin/Condition/MediaIsPublished.php create mode 100644 src/Plugin/Condition/TaxonomyTermIsPublished.php diff --git a/src/Plugin/Condition/MediaIsPublished.php b/src/Plugin/Condition/MediaIsPublished.php new file mode 100644 index 0000000..d698d12 --- /dev/null +++ b/src/Plugin/Condition/MediaIsPublished.php @@ -0,0 +1,96 @@ +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() { + $media = $this->getContextValue('media'); + if (!$media && !$this->isNegated()) { + return FALSE; + } + elseif (!$media) { + return FALSE; + } + else { + return $media->isPublished(); + } + } + + /** + * {@inheritdoc} + */ + public function summary() { + if (!empty($this->configuration['negate'])) { + return $this->t('The media is not published.'); + } + else { + return $this->t('The media is published.'); + } + } + +} + diff --git a/src/Plugin/Condition/TaxonomyTermIsPublished.php b/src/Plugin/Condition/TaxonomyTermIsPublished.php new file mode 100644 index 0000000..48f6921 --- /dev/null +++ b/src/Plugin/Condition/TaxonomyTermIsPublished.php @@ -0,0 +1,96 @@ +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() { + $taxonomy_term = $this->getContextValue('taxonomy_term'); + if (!$taxonomy_term && !$this->isNegated()) { + return FALSE; + } + elseif (!$taxonomy_term) { + return FALSE; + } + else { + return $taxonomy_term->isPublished(); + } + } + + /** + * {@inheritdoc} + */ + public function summary() { + if (!empty($this->configuration['negate'])) { + return $this->t('The taxonomy term is not published.'); + } + else { + return $this->t('The taxonomy term is published.'); + } + } + +} +