From d156a343d92b3107d30ed17e6a2d5af6127ae0fd Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Tue, 1 Oct 2024 15:14:44 -0300 Subject: [PATCH] Add term_is_published and media_is_published conditions. --- islandora.module | 2 + src/Plugin/Condition/MediaIsPublished.php | 95 +++++++++++++++++++++++ src/Plugin/Condition/TermIsPublished.php | 95 +++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 src/Plugin/Condition/MediaIsPublished.php create mode 100644 src/Plugin/Condition/TermIsPublished.php diff --git a/islandora.module b/islandora.module index 153eb1679..1127f562e 100644 --- a/islandora.module +++ b/islandora.module @@ -505,6 +505,7 @@ function islandora_form_block_form_alter(&$form, FormStateInterface $form_state, unset($form['visibility']['media_has_mimetype']); unset($form['visibility']['media_has_term']); unset($form['visibility']['media_is_islandora_media']); + unset($form['visibility']['media_is_published']); unset($form['visibility']['media_uses_filesystem']); unset($form['visibility']['node_had_namespace']); unset($form['visibility']['node_has_ancestor']); @@ -513,6 +514,7 @@ function islandora_form_block_form_alter(&$form, FormStateInterface $form_state, unset($form['visibility']['node_is_islandora_object']); unset($form['visibility']['node_referenced_by_node']); unset($form['visibility']['parent_node_has_term']); + unset($form['visibility']['term_is_published']); } /** diff --git a/src/Plugin/Condition/MediaIsPublished.php b/src/Plugin/Condition/MediaIsPublished.php new file mode 100644 index 000000000..c2390f3a6 --- /dev/null +++ b/src/Plugin/Condition/MediaIsPublished.php @@ -0,0 +1,95 @@ +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_media = $this->getContextValue('taxonomy_media'); + if (!$taxonomy_media && !$this->isNegated()) { + return FALSE; + } + elseif (!$taxonomy_media) { + return FALSE; + } + else { + return $taxonomy_media->isPublished(); + } + } + + /** + * {@inheritdoc} + */ + public function summary() { + if (!empty($this->configuration['negate'])) { + return $this->t('The taxonomy media is not published.'); + } + else { + return $this->t('The taxonomy media is published.'); + } + } + +} diff --git a/src/Plugin/Condition/TermIsPublished.php b/src/Plugin/Condition/TermIsPublished.php new file mode 100644 index 000000000..2707a3811 --- /dev/null +++ b/src/Plugin/Condition/TermIsPublished.php @@ -0,0 +1,95 @@ +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.'); + } + } + +}