Browse Source

Issue 1290 fix (#176)

* Issue 1290 fix

* Add additional line of comment to reduce line length
pull/729/head
Debbie Flitner 5 years ago committed by dannylamb
parent
commit
2a3b556a9e
  1. 4
      src/EventSubscriber/LinkHeaderSubscriber.php
  2. 5
      src/EventSubscriber/NodeLinkHeaderSubscriber.php
  3. 10
      src/Plugin/ContextReaction/JsonldTypeAlterReaction.php

4
src/EventSubscriber/LinkHeaderSubscriber.php

@ -214,8 +214,8 @@ abstract class LinkHeaderSubscriber implements EventSubscriberInterface {
// it becomes the taxonomy term's local uri. // it becomes the taxonomy term's local uri.
if ($referencedEntity->getEntityTypeId() == 'taxonomy_term') { if ($referencedEntity->getEntityTypeId() == 'taxonomy_term') {
$rel = "tag"; $rel = "tag";
if ($referencedEntity->hasField('field_external_uri')) { if ($referencedEntity->hasField(IslandoraUtils::EXTERNAL_URI_FIELD)) {
$external_uri = $referencedEntity->get('field_external_uri')->getValue(); $external_uri = $referencedEntity->get(IslandoraUtils::EXTERNAL_URI_FIELD)->getValue();
if (!empty($external_uri) && isset($external_uri[0]['uri'])) { if (!empty($external_uri) && isset($external_uri[0]['uri'])) {
$entity_url = $external_uri[0]['uri']; $entity_url = $external_uri[0]['uri'];
} }

5
src/EventSubscriber/NodeLinkHeaderSubscriber.php

@ -3,6 +3,7 @@
namespace Drupal\islandora\EventSubscriber; namespace Drupal\islandora\EventSubscriber;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\islandora\IslandoraUtils;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -50,8 +51,8 @@ class NodeLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSubs
foreach ($this->utils->getMedia($node) as $media) { foreach ($this->utils->getMedia($node) as $media) {
$url = $this->utils->getEntityUrl($media); $url = $this->utils->getEntityUrl($media);
foreach ($media->referencedEntities() as $term) { foreach ($media->referencedEntities() as $term) {
if ($term->getEntityTypeId() == 'taxonomy_term' && $term->hasField('field_external_uri')) { if ($term->getEntityTypeId() == 'taxonomy_term' && $term->hasField(IslandoraUtils::EXTERNAL_URI_FIELD)) {
$field = $term->get('field_external_uri'); $field = $term->get(IslandoraUtils::EXTERNAL_URI_FIELD);
if (!$field->isEmpty()) { if (!$field->isEmpty()) {
$link = $field->first()->getValue(); $link = $field->first()->getValue();
$uri = $link['uri']; $uri = $link['uri'];

10
src/Plugin/ContextReaction/JsonldTypeAlterReaction.php

@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\islandora\ContextReaction\NormalizerAlterReaction; use Drupal\islandora\ContextReaction\NormalizerAlterReaction;
use Drupal\jsonld\Normalizer\NormalizerBase; use Drupal\jsonld\Normalizer\NormalizerBase;
use Drupal\islandora\IslandoraUtils;
/** /**
* Alter JSON-LD Type context reaction. * Alter JSON-LD Type context reaction.
@ -46,13 +47,14 @@ class JsonldTypeAlterReaction extends NormalizerAlterReaction {
if ($elem['@id'] === $this->getSubjectUrl($entity)) { if ($elem['@id'] === $this->getSubjectUrl($entity)) {
foreach ($entity->get($config['source_field'])->getValue() as $type) { foreach ($entity->get($config['source_field'])->getValue() as $type) {
// If the configured field is using an entity reference, // If the configured field is using an entity reference,
// we will see if it uses the core config's field_external_uri. // we will see if it uses the core config's
// IslandoraUtils::EXTERNAL_URI_FIELD.
if (array_key_exists('target_id', $type)) { if (array_key_exists('target_id', $type)) {
$target_type = $entity->get($config['source_field'])->getFieldDefinition()->getSetting('target_type'); $target_type = $entity->get($config['source_field'])->getFieldDefinition()->getSetting('target_type');
$referenced_entity = \Drupal::entityTypeManager()->getStorage($target_type)->load($type['target_id']); $referenced_entity = \Drupal::entityTypeManager()->getStorage($target_type)->load($type['target_id']);
if ($referenced_entity->hasField('field_external_uri') && if ($referenced_entity->hasField(IslandoraUtils::EXTERNAL_URI_FIELD) &&
!empty($referenced_entity->get('field_external_uri')->getValue())) { !empty($referenced_entity->get(IslandoraUtils::EXTERNAL_URI_FIELD)->getValue())) {
foreach ($referenced_entity->get('field_external_uri')->getValue() as $value) { foreach ($referenced_entity->get(IslandoraUtils::EXTERNAL_URI_FIELD)->getValue() as $value) {
$elem['@type'][] = $value['uri']; $elem['@type'][] = $value['uri'];
} }
} }

Loading…
Cancel
Save