Browse Source
* Work on #1270. * Remove cruft. * Remove more cruft. * Removed extra comma. * Changed 'context' to 'context_definitions'. * Added additional Context Condition, MediaIsIslandoraMedia. * Removed the node_is_islandora_object and media_is_islandora_media Conditions from the core block placement UI.pull/729/head
Mark Jordan
5 years ago
committed by
dannylamb
3 changed files with 120 additions and 0 deletions
@ -0,0 +1,59 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Drupal\islandora\Plugin\Condition; |
||||||
|
|
||||||
|
use Drupal\Core\Condition\ConditionPluginBase; |
||||||
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks if media entity has fields that qualify it as an "Islandora" media. |
||||||
|
* |
||||||
|
* @Condition( |
||||||
|
* id = "media_is_islandora_media", |
||||||
|
* label = @Translation("Media is an Islandora media"), |
||||||
|
* context_definitions = { |
||||||
|
* "media" = @ContextDefinition("entity:media", required = TRUE , label = @Translation("media")) |
||||||
|
* } |
||||||
|
* ) |
||||||
|
*/ |
||||||
|
class MediaIsIslandoraMedia extends ConditionPluginBase implements ContainerFactoryPluginInterface { |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
||||||
|
return new static( |
||||||
|
$configuration, |
||||||
|
$plugin_id, |
||||||
|
$plugin_definition |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function evaluate() { |
||||||
|
$media = $this->getContextValue('media'); |
||||||
|
if (!$media) { |
||||||
|
return FALSE; |
||||||
|
} |
||||||
|
// Islandora Media have these two fields. |
||||||
|
if ($media->hasField('field_media_use') && $media->hasField('field_media_of')) { |
||||||
|
return TRUE; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function summary() { |
||||||
|
if (!empty($this->configuration['negate'])) { |
||||||
|
return $this->t('The media is not an Islandora media.'); |
||||||
|
} |
||||||
|
else { |
||||||
|
return $this->t('The media is an Islandora media.'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Drupal\islandora\Plugin\Condition; |
||||||
|
|
||||||
|
use Drupal\Core\Condition\ConditionPluginBase; |
||||||
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Checks whether node has fields that qualify it as an "Islandora" node. |
||||||
|
* |
||||||
|
* @Condition( |
||||||
|
* id = "node_is_islandora_object", |
||||||
|
* label = @Translation("Node is an Islandora object"), |
||||||
|
* context_definitions = { |
||||||
|
* "node" = @ContextDefinition("entity:node", required = TRUE , label = @Translation("node")) |
||||||
|
* } |
||||||
|
* ) |
||||||
|
*/ |
||||||
|
class NodeIsIslandoraObject extends ConditionPluginBase implements ContainerFactoryPluginInterface { |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { |
||||||
|
return new static( |
||||||
|
$configuration, |
||||||
|
$plugin_id, |
||||||
|
$plugin_definition |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function evaluate() { |
||||||
|
$node = $this->getContextValue('node'); |
||||||
|
if (!$node) { |
||||||
|
return FALSE; |
||||||
|
} |
||||||
|
// Islandora objects have these two fields. |
||||||
|
if ($node->hasField('field_model') && $node->hasField('field_member_of')) { |
||||||
|
return TRUE; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function summary() { |
||||||
|
if (!empty($this->configuration['negate'])) { |
||||||
|
return $this->t('The node is not an Islandora object.'); |
||||||
|
} |
||||||
|
else { |
||||||
|
return $this->t('The node is an Islandora object.'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue