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.
if ($referencedEntity->getEntityTypeId() == 'taxonomy_term') {
$rel = "tag";
if ($referencedEntity->hasField('field_external_uri')) {
$external_uri = $referencedEntity->get('field_external_uri')->getValue();
if ($referencedEntity->hasField(IslandoraUtils::EXTERNAL_URI_FIELD)) {
$external_uri = $referencedEntity->get(IslandoraUtils::EXTERNAL_URI_FIELD)->getValue();
if (!empty($external_uri) && isset($external_uri[0]['uri'])) {
$entity_url = $external_uri[0]['uri'];
}

5
src/EventSubscriber/NodeLinkHeaderSubscriber.php

@ -3,6 +3,7 @@
namespace Drupal\islandora\EventSubscriber;
use Drupal\node\NodeInterface;
use Drupal\islandora\IslandoraUtils;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -50,8 +51,8 @@ class NodeLinkHeaderSubscriber extends LinkHeaderSubscriber implements EventSubs
foreach ($this->utils->getMedia($node) as $media) {
$url = $this->utils->getEntityUrl($media);
foreach ($media->referencedEntities() as $term) {
if ($term->getEntityTypeId() == 'taxonomy_term' && $term->hasField('field_external_uri')) {
$field = $term->get('field_external_uri');
if ($term->getEntityTypeId() == 'taxonomy_term' && $term->hasField(IslandoraUtils::EXTERNAL_URI_FIELD)) {
$field = $term->get(IslandoraUtils::EXTERNAL_URI_FIELD);
if (!$field->isEmpty()) {
$link = $field->first()->getValue();
$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\islandora\ContextReaction\NormalizerAlterReaction;
use Drupal\jsonld\Normalizer\NormalizerBase;
use Drupal\islandora\IslandoraUtils;
/**
* Alter JSON-LD Type context reaction.
@ -46,13 +47,14 @@ class JsonldTypeAlterReaction extends NormalizerAlterReaction {
if ($elem['@id'] === $this->getSubjectUrl($entity)) {
foreach ($entity->get($config['source_field'])->getValue() as $type) {
// 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)) {
$target_type = $entity->get($config['source_field'])->getFieldDefinition()->getSetting('target_type');
$referenced_entity = \Drupal::entityTypeManager()->getStorage($target_type)->load($type['target_id']);
if ($referenced_entity->hasField('field_external_uri') &&
!empty($referenced_entity->get('field_external_uri')->getValue())) {
foreach ($referenced_entity->get('field_external_uri')->getValue() as $value) {
if ($referenced_entity->hasField(IslandoraUtils::EXTERNAL_URI_FIELD) &&
!empty($referenced_entity->get(IslandoraUtils::EXTERNAL_URI_FIELD)->getValue())) {
foreach ($referenced_entity->get(IslandoraUtils::EXTERNAL_URI_FIELD)->getValue() as $value) {
$elem['@type'][] = $value['uri'];
}
}

Loading…
Cancel
Save