diff --git a/core/modules/path/path.services.yml b/core/modules/path/path.services.yml index c7a95c1a58..8338fb16e1 100644 --- a/core/modules/path/path.services.yml +++ b/core/modules/path/path.services.yml @@ -1,9 +1,9 @@ services: serializer.normalizer.path_field: - class: Drupal\path\Normalizer\PathFieldNormalizer + class: Drupal\path\Normalizer\PathFieldItemNormalizer tags: - { name: normalizer, priority: 10 } serializer.normalizer.path_field.hal: - class: Drupal\path\Normalizer\HalPathFieldNormalizer + class: Drupal\path\Normalizer\HalPathFieldItemNormalizer tags: - { name: normalizer, priority: 15 } diff --git a/core/modules/path/src/Normalizer/PathFieldItemNormalizer.php b/core/modules/path/src/Normalizer/PathFieldItemNormalizer.php index b782bab9fc..b88ab483f2 100644 --- a/core/modules/path/src/Normalizer/PathFieldItemNormalizer.php +++ b/core/modules/path/src/Normalizer/PathFieldItemNormalizer.php @@ -2,18 +2,18 @@ namespace Drupal\path\Normalizer; -use Drupal\path\Plugin\Field\FieldType\PathFieldItemList; +use Drupal\path\Plugin\Field\FieldType\PathItem; use Drupal\serialization\Normalizer\FieldItemNormalizer; /** * PathItem specific normalizer. */ -class PathFieldNormalizer extends FieldItemNormalizer { +class PathFieldItemNormalizer extends FieldItemNormalizer { /** * {@inheritdoc} */ - protected $supportedInterfaceOrClass = PathFieldItemList::class; + protected $supportedInterfaceOrClass = PathItem::class; /** * {@inheritdoc} @@ -24,10 +24,11 @@ public function normalize($object, $format = NULL, array $context = array()) { // If there is an entity associated with this path item, attempt to just // load the alias. if ($entity = $object->getEntity()) { - $alias = \Drupal::service('path.alias_storage')->lookupPathAlias('/' . $entity->toUrl()->getInternalPath(), $entity->language()->getId()); + $langcode = isset($context['langcode']) ? $context['langcode'] : $entity->language()->getId(); + $alias = \Drupal::service('path.alias_storage')->lookupPathAlias('/' . $entity->toUrl()->getInternalPath(), $langcode); // Mimic the field structure that would be returned if this field // contained any items. - $normalized[0]['alias'] = $alias; + $normalized['alias'] = $alias; } return $normalized;