' . t('About') . ''; $output .= '
' . t('Enables Technical Metadata derivative generation') . '
'; return $output; default: } } /** * Implements hook_install(). */ function islandora_fits_install() { $term_name = 'FITS File'; $test_terms = taxonomy_term_load_multiple_by_name($term_name); if (!$test_terms) { $term = Term::create(array( 'parent' => [], 'name' => $term_name, 'vid' => 'islandora_media_use', 'description' => 'Technical Metadata associated with an original media file', 'field_external_uri' => ['uri' => 'https://projects.iq.harvard.edu/fits'], ))->save(); } } /** * Implements hook_theme(). */ function islandora_fits_theme($existing, $type, $theme, $path) { return [ 'fits' => [ 'variables' => [ 'title' => 'FITS data', 'link' => NULL, 'output' => [], ], ], ]; } /** * Implements hook_ENTITY_TYPE_presave(). */ function islandora_fits_media_presave(MediaInterface $media) { $transformer = \Drupal::getContainer()->get('islandora_fits.transformxml'); if ($media->bundle() != 'fits_technical_metadata') { return; } $attached = $media->get('field_attached_fits_node')->referencedEntities()[0]; $data_of = $media->get('field_media_of')->referencedEntities()[0]; $title = $data_of->getTitle(); if (!$attached) { $node = Node::create(['type' => 'fits_technical_metadata']); $node->setTitle("Fits Metadata of $title"); $node->save(); $media->field_attached_fits_node->target_id = $node->id(); $attached = $node; } $file_id = $media->get('field_media_file')->getValue()[0]['target_id']; $file = File::load($file_id); $data = file_get_contents($file->getFileUri()); $transformer->add_node_fields($data); $transformer->populate_node($data, $attached); $attached->save(); }