Browse Source

Work on #1270. (#164)

* 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
parent
commit
58598232b5
  1. 2
      islandora.module
  2. 59
      src/Plugin/Condition/MediaIsIslandoraMedia.php
  3. 59
      src/Plugin/Condition/NodeIsIslandoraObject.php

2
islandora.module

@ -352,6 +352,8 @@ function islandora_form_block_form_alter(&$form, FormStateInterface $form_state,
unset($form['visibility']['node_has_parent']); unset($form['visibility']['node_has_parent']);
unset($form['visibility']['media_uses_filesystem']); unset($form['visibility']['media_uses_filesystem']);
unset($form['visibility']['media_has_mimetype']); unset($form['visibility']['media_has_mimetype']);
unset($form['visibility']['node_is_islandora_object']);
unset($form['visibility']['media_is_islandora_media']);
} }
/** /**

59
src/Plugin/Condition/MediaIsIslandoraMedia.php

@ -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.');
}
}
}

59
src/Plugin/Condition/NodeIsIslandoraObject.php

@ -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…
Cancel
Save