Compare commits

...

9 Commits
2.x ... master

Author SHA1 Message Date
Willow Gillingham 988a1d989a
check that the underlying entity has the parent reference field before trying to get() it (#979) 1 year ago
Mark Jordan cd1ff00905
Work on #1549 and #1550. (#782) 4 years ago
Mark Jordan b292e6c197
Issue 1521: Provide a way for repo admins to see RDF mappings (#778) 4 years ago
dannylamb 77afd8dfb0 Merge branch '8.x-1.x' of github.com:Islandora/islandora 4 years ago
dannylamb 7b085d1e24 Merge branch '8.x-1.x' 4 years ago
dannylamb 19c2e51433 Merge branch '8.x-1.x' 4 years ago
dannylamb 8dc842af22 Merge branch '8.x-1.x' of github.com:Islandora/islandora 5 years ago
dannylamb 796f9ccab2 Merge branch '8.x-1.x' 5 years ago
dannylamb b20e1a69f0 Version 1.1.0 5 years ago
  1. 4
      composer.json
  2. 7
      islandora.links.menu.yml
  3. 9
      islandora.routing.yml
  4. 155
      src/Controller/RdfMappingsReportController.php
  5. 5
      src/IslandoraUtils.php
  6. 4
      src/Plugin/Condition/NodeHasParent.php

4
composer.json

@ -16,7 +16,7 @@
"require": {
"drupal/context": "^4.0",
"drupal/search_api": "~1.8",
"islandora/jsonld": "dev-8.x-1.x",
"islandora/jsonld": "1.1.0",
"stomp-php/stomp-php": "4.*",
"drupal/jwt": "1.0.0-beta1",
"drupal/filehash": "^1.1",
@ -28,7 +28,7 @@
"drupal/migrate_source_csv" : "^2.1",
"drupal/token" : "^1.3",
"drupal/flysystem" : "^1.0",
"islandora/crayfish-commons": "dev-dev"
"islandora/crayfish-commons": "1.1.0"
},
"require-dev": {
"phpunit/phpunit": "^6",

7
islandora.links.menu.yml

@ -11,3 +11,10 @@ system.islandora_settings:
parent: system.admin_config_islandora
route_name: system.islandora_settings
description: 'Confgure core Islandora settings'
# RDF property mappings
system.islandora_rdf_mappings:
title: 'Field and term RDF mappings'
parent: system.admin_reports
description: 'List of configured Drupal field to RDF property mappings and taxonomy term linked data URIs.'
route_name: system.islandora_rdf_mappings

9
islandora.routing.yml

@ -16,6 +16,15 @@ system.islandora_settings:
requirements:
_permission: 'administer site configuration'
# RDF properties report
system.islandora_rdf_mappings:
path: '/admin/reports/islandora/rdf_mappings'
defaults:
_controller: '\Drupal\islandora\Controller\RdfMappingsReportController::main'
_title: 'Field and term RDF mappings'
requirements:
_permission: 'administer site configuration'
islandora.add_member_to_node_page:
path: '/node/{node}/members/add'
defaults:

155
src/Controller/RdfMappingsReportController.php

@ -0,0 +1,155 @@
<?php
namespace Drupal\islandora\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* RDF mappings report controller.
*/
class RdfMappingsReportController extends ControllerBase {
/**
* Output the RDF mappings report.
*
* @return string
* Markup of the tables.
*/
public function main() {
$markup = '';
// Configured namespaces.
$namespaces = rdf_get_namespaces();
$namespaces_table_rows = [];
foreach ($namespaces as $alias => $namespace_uri) {
$namespaces_table_rows[] = [$alias, $namespace_uri];
}
$namespaces_table_header = [t('Namespace alias'), t('Namespace URI')];
$namespaces_table = [
'#theme' => 'table',
'#header' => $namespaces_table_header,
'#rows' => $namespaces_table_rows,
];
$namespaces_table_markup = \Drupal::service('renderer')->render($namespaces_table);
$markup .= '<details><summary>' . t('RDF namespaces used in field mappings') .
'</summary><div class="details-wrapper">' . $namespaces_table_markup . '</div></details>';
// Node and media field to RDF property mappings.
$entity_types = ['node', 'media'];
$markup .= '<h2>' . t('Field mappings') . '</h2>';
foreach ($entity_types as $entity_type) {
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type);
foreach ($bundles as $name => $attr) {
$rdf_mappings = rdf_get_mapping($entity_type, $name);
$rdf_types = $rdf_mappings->getPreparedBundleMapping();
if (array_key_exists('types', $rdf_types) && count($rdf_types['types']) > 0) {
$rdf_types = implode(', ', $rdf_types['types']);
$markup .= '<h3>' . $attr['label'] . ' (' . $entity_type . ')' . ', mapped to RDF type ' . $rdf_types . '</h3>';
}
else {
$markup .= '<h3>' . $attr['label'] . ' (' . $entity_type . ') - no RDF type mapping</h3>';
}
$fields = \Drupal::entityManager()->getFieldDefinitions($entity_type, $name);
$mappings_table_rows = [];
foreach ($fields as $field_name => $field_object) {
$field_mappings = $rdf_mappings->getPreparedFieldMapping($field_name);
if (array_key_exists('properties', $field_mappings)) {
$properties = implode(', ', $field_mappings['properties']);
$mappings_table_rows[] = [$field_object->getLabel() . ' (' . $field_name . ')', $properties];
}
}
$mappings_header = [t('Drupal field'), t('RDF property')];
if (count($mappings_table_rows) == 0) {
$mappings_header = [];
$mappings_table_rows[] = [t('No RDF mappings configured for @bundle.', ['@bundle' => $attr['label']])];
}
$mappings_table = [
'#theme' => 'table',
'#header' => $mappings_header,
'#rows' => $mappings_table_rows,
];
$mappings_table_markup = \Drupal::service('renderer')->render($mappings_table);
$markup .= $mappings_table_markup;
}
}
// Taxonomy terms with external URIs or authority links.
$markup .= '<h2>' . t('Taxonomy terms with external URIs or authority links') . '</h2>';
$utils = \Drupal::service('islandora.utils');
$uri_fields = $utils->getUriFieldNamesForTerms();
$vocabs = Vocabulary::loadMultiple();
foreach ($vocabs as $vid => $vocab) {
$rdf_mappings = rdf_get_mapping('taxonomy_term', $vid);
$rdf_types = $rdf_mappings->getPreparedBundleMapping();
$vocab_table_header = [];
$vocab_table_rows = [];
if (array_key_exists('types', $rdf_types) && count($rdf_types['types']) > 0) {
$rdf_types = implode(', ', $rdf_types['types']);
$markup .= '<h3>' . $vocab->label() . ' (' . $vid . ')' . ', mapped to RDF type ' . $rdf_types . '</h3>';
}
else {
$markup .= '<h3>' . $vocab->label() . ' (' . $vid . ') - no RDF type mapping</h3>';
}
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
if (count($terms) == 0) {
$vocab_table_rows[] = [t('No terms in this vocabulary.')];
$vocab_table = [
'#theme' => 'table',
'#header' => $vocab_table_header,
'#rows' => $vocab_table_rows,
];
$vocab_table_markup = \Drupal::service('renderer')->render($vocab_table);
$markup .= $vocab_table_markup;
}
else {
$vocab_table_header = [
t('Term'),
t('Term ID'),
t('External URI or Authority link'),
];
$vocab_table_rows = [];
foreach ($terms as $t) {
$ld_uri = NULL;
$term = Term::load($t->tid);
foreach ($uri_fields as $uri_field) {
if ($term->hasField($uri_field) && !$term->get($uri_field)->isEmpty()) {
$ld_uri = $term->get($uri_field)->first()->getValue();
continue;
}
}
if (is_array($ld_uri) && array_key_exists('uri', $ld_uri)) {
$term_link = Link::fromTextAndUrl($term->getName(), Url::fromUri('internal:/taxonomy/term/' . $term->id()));
$vocab_table_rows[] = [
$term_link,
$term->id(),
$ld_uri['uri'],
];
}
else {
$term_link = Link::fromTextAndUrl($term->getName(), Url::fromUri('internal:/taxonomy/term/' . $term->id()));
$vocab_table_rows[] = [$term_link, $term->id(), t('None')];
}
}
$vocab_table = [
'#theme' => 'table',
'#header' => $vocab_table_header,
'#rows' => $vocab_table_rows,
];
}
$vocab_table_markup = \Drupal::service('renderer')->render($vocab_table);
$markup .= $vocab_table_markup;
}
return ['#markup' => $markup];
}
}

5
src/IslandoraUtils.php

@ -265,7 +265,7 @@ class IslandoraUtils {
}
/**
* Gets the taxonomy term associated with an external uri.
* Gets the external uri associated with a taxonomy term.
*
* @param \Drupal\taxonomy\TermInterface $term
* Taxonomy term.
@ -302,7 +302,8 @@ class IslandoraUtils {
$field_map = $this->entityFieldManager->getFieldMap();
$fields = [];
foreach ($field_map['taxonomy_term'] as $field_name => $field_data) {
if ($field_data['type'] == 'authority_link') {
$data_types = ['authority_link', 'field_external_authority_link'];
if (in_array($field_data['type'], $data_types)) {
$fields[] = $field_name;
}
}

4
src/Plugin/Condition/NodeHasParent.php

@ -137,9 +137,9 @@ class NodeHasParent extends ConditionPluginBase implements ContainerFactoryPlugi
* TRUE if entity references the specified parent.
*/
protected function evaluateEntity(EntityInterface $entity) {
foreach ($entity->referencedEntities() as $referenced_entity) {
if ($entity->getEntityTypeID() == 'node' && $referenced_entity->getEntityTypeId() == 'node') {
$parent_reference_field = $this->configuration['parent_reference_field'];
foreach ($entity->referencedEntities() as $referenced_entity) {
if ($entity->getEntityTypeID() == 'node' && $referenced_entity->getEntityTypeId() == 'node' && $entity->hasField($parent_reference_field)) {
$field = $entity->get($parent_reference_field);
if (!$field->isEmpty()) {
$nids = $field->getValue();

Loading…
Cancel
Save