diff --git a/modules/islandora_text_extraction/islandora_text_extraction.module b/modules/islandora_text_extraction/islandora_text_extraction.module index 2b2c1a5d..a9440c90 100644 --- a/modules/islandora_text_extraction/islandora_text_extraction.module +++ b/modules/islandora_text_extraction/islandora_text_extraction.module @@ -44,6 +44,28 @@ function islandora_text_extraction_media_presave(MediaInterface $media) { } } +/** + * Implements hook_media_insert(). + */ +function islandora_text_extraction_media_insert(MediaInterface $media) { + if ($media->bundle() != 'extracted_text') { + return; + } + + \Drupal::service('islandora_text_extraction.search_reindexer')->reindexParent($media); +} + +/** + * Implements hook_media_update(). + */ +function islandora_text_extraction_media_update(MediaInterface $media) { + if ($media->bundle() != 'extracted_text') { + return; + } + + \Drupal::service('islandora_text_extraction.search_reindexer')->reindexParent($media); +} + /** * Implements hook_form_form_id_alter(). */ diff --git a/modules/islandora_text_extraction/islandora_text_extraction.services.yml b/modules/islandora_text_extraction/islandora_text_extraction.services.yml new file mode 100644 index 00000000..72d63bdf --- /dev/null +++ b/modules/islandora_text_extraction/islandora_text_extraction.services.yml @@ -0,0 +1,8 @@ +services: + logger.channel.islandora_text_extraction: + parent: logger.channel_base + arguments: ['islandora_text_extraction'] + islandora_text_extraction.search_reindexer: + class: Drupal\islandora_text_extraction\SearchReindexer + arguments: ['@islandora.utils', '@logger.channel.islandora_text_extraction'] + diff --git a/modules/islandora_text_extraction/src/SearchReindexer.php b/modules/islandora_text_extraction/src/SearchReindexer.php new file mode 100644 index 00000000..791cf9e9 --- /dev/null +++ b/modules/islandora_text_extraction/src/SearchReindexer.php @@ -0,0 +1,65 @@ +utils = $utils; + $this->logger = $logger; + } + + /** + * Reindexes parent node for a media. No-op if parent does not exist. + * + * @param Drupal\media\MediaInterface $media + * Media whose parent you want to reindex. + */ + public function reindexParent(MediaInterface $media) { + $parent = $this->utils->getParentNode($media); + + if ($parent === NULL) { + return; + } + + $this->logger->debug( + "Re-indexing parent node @nid for extracted text @mid using the search_api", + ['@nid' => $parent->id(), '@mid' => $media->id()] + ); + + $parent->original = $parent; + search_api_entity_update($parent); + } + +} diff --git a/modules/islandora_text_extraction_defaults/config/install/rdf.mapping.media.extracted_text.yml b/modules/islandora_text_extraction_defaults/config/install/rdf.mapping.media.extracted_text.yml new file mode 100644 index 00000000..e0a0b155 --- /dev/null +++ b/modules/islandora_text_extraction_defaults/config/install/rdf.mapping.media.extracted_text.yml @@ -0,0 +1,51 @@ +langcode: en +status: true +dependencies: + config: + - media.type.extracted_text + enforced: + module: + - islandora_text_extraction_defaults + module: + - media +id: media.extracted_text +targetEntityType: media +bundle: extracted_text +types: + - 'pcdm:File' +fieldMappings: + name: + properties: + - 'dcterms:title' + - 'rdf:label' + created: + properties: + - 'schema:dateCreated' + datatype_callback: + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' + changed: + properties: + - 'schema:dateModified' + datatype_callback: + callable: 'Drupal\rdf\CommonDataConverter::dateIso8601Value' + uid: + properties: + - 'schema:author' + mapping_type: rel + field_mime_type: + properties: + - 'ebucore:hasMimeType' + field_media_of: + properties: + - 'pcdm:fileOf' + mapping_type: rel + field_original_name: + properties: + - 'premis3:originalName' + field_tags: + properties: + - 'schema:additionalType' + mapping_type: rel + field_file_size: + properties: + - 'premis:hasSize' diff --git a/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php b/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php index ae4bc55a..b2e757ff 100644 --- a/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php +++ b/src/Plugin/ContextReaction/JsonldTypeAlterReaction.php @@ -44,6 +44,9 @@ class JsonldTypeAlterReaction extends NormalizerAlterReaction { // Search for the entity in the graph. foreach ($normalized['@graph'] as &$elem) { + if (!is_array($elem['@type'])) { + $elem['@type'] = [$elem['@type']]; + } if ($elem['@id'] === $this->getSubjectUrl($entity)) { foreach ($entity->get($config['source_field'])->getValue() as $type) { // If the configured field is using an entity reference,