Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Context Conditions for term_is_published and media_is_published. #1058

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions islandora.module
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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']);
}

/**
Expand Down
95 changes: 95 additions & 0 deletions src/Plugin/Condition/MediaIsPublished.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Drupal\islandora\Plugin\Condition;

use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides an 'Is Published' condition for media.
*
* @Condition(
* id = "media_is_published",
* label = @Translation("Media is published"),
* context_definitions = {
* "media" = @ContextDefinition("entity:media", required = TRUE , label = @Translation("media"))
* }
* )
*/
class MediaIsPublished extends ConditionPluginBase implements ContainerFactoryPluginInterface {

/**
* Term storage.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
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\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
EntityTypeManagerInterface $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() {
$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.');
}
}

}
95 changes: 95 additions & 0 deletions src/Plugin/Condition/TermIsPublished.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Drupal\islandora\Plugin\Condition;

use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides an 'Is Published' condition for taxonomy terms.
*
* @Condition(
* id = "term_is_published",
* label = @Translation("Term is published"),
* context_definitions = {
* "taxonomy_term" = @ContextDefinition("entity:taxonomy_term", required = TRUE , label = @Translation("taxonomy term"))
* }
* )
*/
class TermIsPublished extends ConditionPluginBase implements ContainerFactoryPluginInterface {

/**
* Term storage.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
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\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
EntityTypeManagerInterface $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() {
$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.');
}
}

}