https://github.com/diegopino */ use Drupal\Core\Database\IntegrityConstraintViolationException; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_help(). */ function islandora_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { // Main module help for the islandora module. case 'help.page.islandora': $output = ''; $output .= '

' . t('About') . '

'; $output .= '

' . t('This is a placeholder for future help text about Islandora.') . '

'; return $output; default: } } /** * Implements hook_theme(). */ function islandora_theme() { $theme = []; $theme['fedora_resource'] = [ 'render element' => 'elements', 'file' => 'fedora_resource.page.inc', 'template' => 'fedora_resource', ]; $theme['fedora_resource_content_add_list'] = [ 'render element' => 'content', 'variables' => ['content' => NULL], 'file' => 'fedora_resource.page.inc', ]; return $theme; } /** * Implements hook_theme_suggestions_HOOK(). */ function islandora_theme_suggestions_fedora_resource(array $variables) { $suggestions = []; $entity = $variables['elements']['#fedora_resource']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'fedora_resource__' . $sanitized_view_mode; $suggestions[] = 'fedora_resource__' . $entity->bundle(); $suggestions[] = 'fedora_resource__' . $entity->bundle() . '__' . $sanitized_view_mode; $suggestions[] = 'fedora_resource__' . $entity->id(); $suggestions[] = 'fedora_resource__' . $entity->id() . '__' . $sanitized_view_mode; return $suggestions; } /** * Implements hook_rdf_namespaces(). */ function islandora_rdf_namespaces() { // Yes, it's amazing, rdf is not registered by default! return [ 'ldp' => 'http://www.w3.org/ns/ldp#', 'dc11' => 'http://purl.org/dc/elements/1.1/', 'nfo' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', 'ebucore' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', 'fedora' => 'http://fedora.info/definitions/v4/repository#', 'owl' => 'http://www.w3.org/2002/07/owl#', 'ore' => 'http://www.openarchives.org/ore/terms/', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'islandora' => 'http://islandora.ca/CLAW/', 'pcdm' => 'http://pcdm.org/models#', ]; } /** * Implements hook_ENTITY_TYPE_insert(). */ function islandora_fedora_resource_insert(EntityInterface $entity) { // Creates a record in the db to track the number of changes to the entity. $versionCounter = \Drupal::service('islandora.versioncounter'); try { $versionCounter->create($entity->uuid()); } catch (IntegrityConstraintViolationException $e) { \Drupal::logger('islandora')->error( 'Attempted to create duplicate entry for @uuid in version counter ' . 'table. This should never happen.', ['@uuid' => $entity->uuid()] ); } } /** * Implements hook_ENTITY_TYPE_update(). */ function islandora_fedora_resource_update(EntityInterface $entity) { // Increments the number of changes to the entity. $versionCounter = \Drupal::service('islandora.versioncounter'); $versionCounter->increment($entity->uuid()); } /** * Implements hook_ENTITY_TYPE_update(). */ function islandora_fedora_resource_delete(EntityInterface $entity) { // Deletes the record in the db to track the number of changes to the entity. $versionCounter = \Drupal::service('islandora.versioncounter'); $versionCounter->delete($entity->uuid()); }