Browse Source

merge 8.x-1.x

d9_islandora
ezoller 4 years ago
parent
commit
ec4ee15637
  1. 37
      islandora.module
  2. 2
      migrate/tags.csv
  3. 2
      src/MediaSource/MediaSourceService.php
  4. 150
      src/Plugin/Condition/NodeReferencedByNode.php

37
islandora.module

@ -120,6 +120,8 @@ function islandora_media_insert(MediaInterface $media) {
$media $media
); );
} }
// Wait until the media insert is complete, then fire file derivatives.
drupal_register_shutdown_function('_islandora_fire_media_file_derivative_reaction', $media);
} }
/** /**
@ -170,16 +172,22 @@ function islandora_media_delete(MediaInterface $media) {
} }
/** /**
* Implements hook_ENTITYTYPE_postsave(). * Helper to fire media derivative file reactions after a media 'insert'.
*
* This function should not be called on its own; it exists as a workaround to
* being unable to fire media events after a media insert operation. This
* behaviour will eventually be replaced by event listeners once these are
* implemented in Drupal 9.
*
* @param \Drupal\Core\Media\MediaInterface $media
* The media that was just inserted.
*
* @see https://www.drupal.org/project/drupal/issues/2551893
*/ */
function islandora_media_postsave(EntityInterface $media, $op) { function _islandora_fire_media_file_derivative_reaction(MediaInterface $media) {
$utils = \Drupal::service('islandora.utils'); $utils = \Drupal::service('islandora.utils');
// Add derived file to the media. // Execute derivative file reactions.
if ($op == 'insert') {
$utils->executeMediaReactions('\Drupal\islandora\Plugin\ContextReaction\DerivativeFileReaction', $media); $utils->executeMediaReactions('\Drupal\islandora\Plugin\ContextReaction\DerivativeFileReaction', $media);
}
} }
/** /**
@ -414,16 +422,17 @@ function islandora_form_block_form_alter(&$form, FormStateInterface $form_state,
// /admin/structure/context instead if you want to use these conditions // /admin/structure/context instead if you want to use these conditions
// to alter block layout. // to alter block layout.
unset($form['visibility']['content_entity_type']); unset($form['visibility']['content_entity_type']);
unset($form['visibility']['parent_node_has_term']);
unset($form['visibility']['node_had_namespace']);
unset($form['visibility']['media_has_term']);
unset($form['visibility']['file_uses_filesystem']); unset($form['visibility']['file_uses_filesystem']);
unset($form['visibility']['node_has_term']);
unset($form['visibility']['node_has_parent']);
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_has_term']);
unset($form['visibility']['media_is_islandora_media']); unset($form['visibility']['media_is_islandora_media']);
unset($form['visibility']['media_uses_filesystem']);
unset($form['visibility']['node_had_namespace']);
unset($form['visibility']['node_has_parent']);
unset($form['visibility']['node_has_term']);
unset($form['visibility']['node_is_islandora_object']);
unset($form['visibility']['node_referenced_by_node']);
unset($form['visibility']['parent_node_has_term']);
} }
/** /**

2
migrate/tags.csv

@ -15,3 +15,5 @@ islandora_models,"Digital Document","An electronic file or document.",https://sc
islandora_models,"Paged Content","An Electronic Book, object with pages",https://schema.org/Book islandora_models,"Paged Content","An Electronic Book, object with pages",https://schema.org/Book
islandora_models,"Page","A page in an Electronic Paged Content Object",http://id.loc.gov/ontologies/bibframe/part islandora_models,"Page","A page in an Electronic Paged Content Object",http://id.loc.gov/ontologies/bibframe/part
islandora_models,"Publication Issue","A part of a successively published publication such as a periodical or publication volume, often numbered, usually containing a grouping of works such as articles.",https://schema.org/PublicationIssue islandora_models,"Publication Issue","A part of a successively published publication such as a periodical or publication volume, often numbered, usually containing a grouping of works such as articles.",https://schema.org/PublicationIssue
islandora_models,"Compound Object","A special type of collection where the parent item may also have complex metadata",http://vocab.getty.edu/aat/300242735
islandora_models,"Newspaper","A special type of collection which only has Newspaper Issues for children.",https://schema.org/Newspaper

1 vid name description external_uri
15 islandora_models Paged Content An Electronic Book, object with pages https://schema.org/Book
16 islandora_models Page A page in an Electronic Paged Content Object http://id.loc.gov/ontologies/bibframe/part
17 islandora_models Publication Issue A part of a successively published publication such as a periodical or publication volume, often numbered, usually containing a grouping of works such as articles. https://schema.org/PublicationIssue
18 islandora_models Compound Object A special type of collection where the parent item may also have complex metadata http://vocab.getty.edu/aat/300242735
19 islandora_models Newspaper A special type of collection which only has Newspaper Issues for children. https://schema.org/Newspaper

2
src/MediaSource/MediaSourceService.php

@ -308,7 +308,7 @@ class MediaSourceService {
// Set alt text. // Set alt text.
if ($source_field_config->getSetting('alt_field') && $source_field_config->getSetting('alt_field_required')) { if ($source_field_config->getSetting('alt_field') && $source_field_config->getSetting('alt_field_required')) {
$media_struct[$source_field]['alt'] = $file->getFilename; $media_struct[$source_field]['alt'] = $file->getFilename();
} }
$media = $this->entityTypeManager->getStorage('media')->create($media_struct); $media = $this->entityTypeManager->getStorage('media')->create($media_struct);

150
src/Plugin/Condition/NodeReferencedByNode.php

@ -0,0 +1,150 @@
<?php
namespace Drupal\islandora\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Condition for a node referenced by another node using the configured field.
*
* @Condition(
* id = "node_referenced_by_node",
* label = @Translation("Node is referenced by other nodes"),
* context = {
* "node" = @ContextDefinition("entity:node", required = TRUE , label = @Translation("node"))
* }
* )
*/
class NodeReferencedByNode extends ConditionPluginBase implements ContainerFactoryPluginInterface {
/**
* Node 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 function defaultConfiguration() {
return parent::defaultConfiguration() + [
'reference_field' => 'field_member_of',
];
}
/**
* {@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 buildConfigurationForm(array $form, FormStateInterface $form_state) {
$field_map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('entity_reference');
$node_fields = array_keys($field_map['node']);
$options = array_combine($node_fields, $node_fields);
$form['reference_field'] = [
'#type' => 'select',
'#title' => t('Field to check for reference to this node'),
'#options' => $options,
'#default_value' => $this->configuration['reference_field'],
'#required' => TRUE,
'#description' => t("Machine name of field that should be checked for references to this node."),
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['reference_field'] = $form_state->getValue('reference_field');
parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function evaluate() {
$node = $this->getContextValue('node');
if (!$node) {
return FALSE;
}
return $this->evaluateEntity($node);
}
/**
* Evaluates if an entity is referenced in the configured node field.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to evaluate.
*
* @return bool
* TRUE if entity is referenced..
*/
protected function evaluateEntity(EntityInterface $entity) {
$reference_field = $this->configuration['reference_field'];
$config = FieldStorageConfig::loadByName('node', $reference_field);
if ($config) {
$id_count = \Drupal::entityQuery('node')
->condition($reference_field, $entity->id())
->count()
->execute();
return ($id_count > 0);
}
}
/**
* {@inheritdoc}
*/
public function summary() {
if (!empty($this->configuration['negate'])) {
return $this->t("The node is not referenced in another node's field `@field`.", ['@field' => $this->configuration['reference_field']]);
}
else {
return $this->t("The node is referenced in another node's field `@field`.", ['@field' => $this->configuration['reference_field']]);
}
}
}
Loading…
Cancel
Save