' . t('About') . ''; $output .= '
' . t('Enables Technical Metadata derivative generation') . '
'; return $output; default: } } /** * 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) { if ($media->bundle() != 'fits_technical_metadata') { return; } $transformer = \Drupal::getContainer()->get('islandora_fits.transformxml'); $media->set('field_complete', TRUE); $file_id = $media->get('field_media_file')->getValue()[0]['target_id']; $file = File::load($file_id); $data = file_get_contents($file->getFileUri()); // Adds any new fields to FITS media type. $has_new = $transformer->checkNew($data); if ($has_new) { $media->set('field_complete', FALSE); } else { $transformer->populateMedia($data, $media); } } /** * Implements hook_media_update(). */ function islandora_fits_media_update(MediaInterface $media) { if ($media->bundle() != 'fits_technical_metadata') { return; } if ($media->get('field_complete')->value == FALSE) { $transformer = \Drupal::getContainer()->get('islandora_fits.transformxml'); $file_id = $media->get('field_media_file')->getValue()[0]['target_id']; $file = File::load($file_id); $data = file_get_contents($file->getFileUri()); $transformer->addMediaFields($data); $new_media = Media::load($media->id()); $new_media->set('field_complete', TRUE); $new_media->save(); } } /** * Implements hook_media_insert(). */ function islandora_fits_media_insert(MediaInterface $media) { if ($media->bundle() != 'fits_technical_metadata') { return; } islandora_fits_media_update($media); } /** * Implements hook_entity_extra_field_info(). */ function islandora_fits_entity_extra_field_info() { $entityFieldManager = \Drupal::service('entity_field.manager'); $node_types = \Drupal\node\Entity\NodeType::loadMultiple(); $extra = []; $types = []; foreach ($node_types as $node_type) { $types[] = $node_type->get('type'); } foreach ($types as $bundle) { $fields = $entityFieldManager->getFieldDefinitions('node', $bundle); if (array_key_exists('field_model', $fields) && array_key_exists('field_member_of', $fields)) { $extra['node'][$bundle]['display']['islandora_fits_checksum'] = [ 'label' => t('File Checksum'), 'description' => t('Checksum as discovered by FITs webservice'), 'weight' => 100, 'visible' => TRUE, ]; } } return $extra; } /** * Implements hook_entity_view(). */ function islandora_fits_entity_view(array &$build, $entity, $display, $view_mode) { $route_match_item = \Drupal::routeMatch()->getParameters()->all(); $current_entity = reset($route_match_item); if ($entity === $current_entity) { $medias = \Drupal::entityQuery( 'media') ->condition('field_media_of', $entity->id()) ->condition('bundle', 'fits_technical_metadata') ->execute(); $mid = \reset($medias); if ($mid) { $fits = Media::load($mid); $checksum = $fits->get('fits_ois_file_information_md5che')->value; if ($checksum) { $build['islandora_fits_checksum'] = [ '#type' => 'container', '#attributes' => [ 'id' => 'field-islandora-checksum', ], 'checksum' => [ '#type' => 'item', '#title' => t('MD5 Checksum'), 'internal_uri' => [ '#type' => 'markup', '#markup' => $checksum, ], ], ]; } } } }