From 0c8337421630f290d671cbd96728a913a073e367 Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Fri, 6 Dec 2024 16:24:18 -0400 Subject: [PATCH 1/2] 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.'); + } + } + +} + From 626d2a281f6b9848278c8a030e9a7bf9365231a7 Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Fri, 6 Dec 2024 16:34:07 -0400 Subject: [PATCH 2/2] Change namespace. --- src/Plugin/Condition/MediaIsPublished.php | 2 +- src/Plugin/Condition/TaxonomyTermIsPublished.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin/Condition/MediaIsPublished.php b/src/Plugin/Condition/MediaIsPublished.php index d698d12..575d212 100644 --- a/src/Plugin/Condition/MediaIsPublished.php +++ b/src/Plugin/Condition/MediaIsPublished.php @@ -1,6 +1,6 @@