Compare commits
2 Commits
main
...
unpublishe
Author | SHA1 | Date |
---|---|---|
Rosie Le Faive | 626d2a281f | 3 weeks ago |
Rosie Le Faive | 0c83374216 | 3 weeks ago |
2 changed files with 192 additions and 0 deletions
@ -0,0 +1,96 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Drupal\islandlives\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() { |
||||||
|
$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.'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,96 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Drupal\islandlives\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 = "taxonomy_term_is_published", |
||||||
|
* label = @Translation("Taxonomy Term is published"), |
||||||
|
* context_definitions = { |
||||||
|
* "taxonomy_term" = @ContextDefinition("entity:taxonomy_term", required = TRUE , label = @Translation("taxonomy term")) |
||||||
|
* } |
||||||
|
* ) |
||||||
|
*/ |
||||||
|
class TaxonomyTermIsPublished 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.'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
Loading…
Reference in new issue