|
|
@ -28,12 +28,22 @@ class JsonldTypeAlterReaction extends NormalizerAlterReaction { |
|
|
|
* {@inheritdoc} |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function execute(EntityInterface $entity = NULL, array &$normalized = NULL, array $context = NULL) { |
|
|
|
public function execute(EntityInterface $entity = NULL, array &$normalized = NULL, array $context = NULL) { |
|
|
|
|
|
|
|
// Check that the source field exists and there's some RDF |
|
|
|
|
|
|
|
// to manipulate. |
|
|
|
$config = $this->getConfiguration(); |
|
|
|
$config = $this->getConfiguration(); |
|
|
|
// Use a pre-configured field as the source of the additional @type. |
|
|
|
$ok = $entity->hasField($config['source_field']) && |
|
|
|
if (($entity->hasField($config['source_field'])) && |
|
|
|
!empty($entity->get($config['source_field'])->getValue()) && |
|
|
|
(!empty($entity->get($config['source_field'])->getValue()))) { |
|
|
|
isset($normalized['@graph']) && |
|
|
|
if (isset($normalized['@graph']) && is_array($normalized['@graph'])) { |
|
|
|
is_array($normalized['@graph']) && |
|
|
|
foreach ($normalized['@graph'] as &$graph) { |
|
|
|
!empty($normalized['@graph']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$ok) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Search for the entity in the graph. |
|
|
|
|
|
|
|
foreach ($normalized['@graph'] as &$elem) { |
|
|
|
|
|
|
|
if ($elem['@id'] === $entity->toUrl()->setAbsolute()->toString() . '?_format=jsonld') { |
|
|
|
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 field_external_uri. |
|
|
@ -43,15 +53,15 @@ class JsonldTypeAlterReaction extends NormalizerAlterReaction { |
|
|
|
if ($referenced_entity->hasField('field_external_uri') && |
|
|
|
if ($referenced_entity->hasField('field_external_uri') && |
|
|
|
!empty($referenced_entity->get('field_external_uri')->getValue())) { |
|
|
|
!empty($referenced_entity->get('field_external_uri')->getValue())) { |
|
|
|
foreach ($referenced_entity->get('field_external_uri')->getValue() as $value) { |
|
|
|
foreach ($referenced_entity->get('field_external_uri')->getValue() as $value) { |
|
|
|
$graph['@type'][] = $value['uri']; |
|
|
|
$elem['@type'][] = $value['uri']; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
$graph['@type'][] = NormalizerBase::escapePrefix($type['value'], $context['namespaces']); |
|
|
|
$elem['@type'][] = NormalizerBase::escapePrefix($type['value'], $context['namespaces']); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|