updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Drupal\hal\LinkManager;
|
||||
|
||||
use Drupal\serialization\Normalizer\CacheableNormalizerInterface;
|
||||
|
||||
/**
|
||||
* Defines an abstract base-class for HAL link manager objects.
|
||||
*/
|
||||
@@ -39,17 +41,32 @@ abstract class LinkManagerBase {
|
||||
/**
|
||||
* Gets the link domain.
|
||||
*
|
||||
* @param array $context
|
||||
* Normalization/serialization context.
|
||||
*
|
||||
* @return string
|
||||
* The link domain.
|
||||
*
|
||||
* @see \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize()
|
||||
* @see \Symfony\Component\Serializer\SerializerInterface::serialize()
|
||||
* @see \Drupal\serialization\Normalizer\CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY
|
||||
*/
|
||||
protected function getLinkDomain() {
|
||||
protected function getLinkDomain(array $context = []) {
|
||||
if (empty($this->linkDomain)) {
|
||||
if ($domain = $this->configFactory->get('hal.settings')->get('link_domain')) {
|
||||
$this->linkDomain = rtrim($domain, '/');
|
||||
// Bubble the appropriate cacheability metadata whenever possible.
|
||||
if (isset($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY])) {
|
||||
$context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheableDependency($this->configFactory->get('hal.settings'));
|
||||
}
|
||||
return rtrim($domain, '/');
|
||||
}
|
||||
else {
|
||||
// Bubble the relevant cacheability metadata whenever possible.
|
||||
if (isset($context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY])) {
|
||||
$context[CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY]->addCacheContexts(['url.site']);
|
||||
}
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
$this->linkDomain = $request->getSchemeAndHttpHost() . $request->getBasePath();
|
||||
return $request->getSchemeAndHttpHost() . $request->getBasePath();
|
||||
}
|
||||
}
|
||||
return $this->linkDomain;
|
||||
|
||||
@@ -68,7 +68,7 @@ class RelationLinkManager extends LinkManagerBase implements RelationLinkManager
|
||||
// module is installed that adds such content, but requires this URL to be
|
||||
// different (e.g., include a language prefix), then the module must also
|
||||
// override the RelationLinkManager class/service to return the desired URL.
|
||||
$uri = $this->getLinkDomain() . "/rest/relation/$entity_type/$bundle/$field_name";
|
||||
$uri = $this->getLinkDomain($context) . "/rest/relation/$entity_type/$bundle/$field_name";
|
||||
$this->moduleHandler->alter('hal_relation_uri', $uri, $context);
|
||||
// @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This
|
||||
// hook is invoked to maintain backwards compatibility
|
||||
|
||||
@@ -69,7 +69,7 @@ class TypeLinkManager extends LinkManagerBase implements TypeLinkManagerInterfac
|
||||
// installed that adds such content, but requires this URL to be different
|
||||
// (e.g., include a language prefix), then the module must also override the
|
||||
// TypeLinkManager class/service to return the desired URL.
|
||||
$uri = $this->getLinkDomain() . "/rest/type/$entity_type/$bundle";
|
||||
$uri = $this->getLinkDomain($context) . "/rest/type/$entity_type/$bundle";
|
||||
$this->moduleHandler->alter('hal_type_uri', $uri, $context);
|
||||
// @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. This
|
||||
// hook is invoked to maintain backwards compatibility
|
||||
|
||||
@@ -6,6 +6,7 @@ use Drupal\Component\Utility\NestedArray;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
|
||||
use Drupal\hal\LinkManager\LinkManagerInterface;
|
||||
use Drupal\serialization\Normalizer\FieldableEntityNormalizerTrait;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
@@ -72,15 +73,10 @@ class ContentEntityNormalizer extends NormalizerBase {
|
||||
],
|
||||
];
|
||||
|
||||
$field_items = TypedDataInternalPropertiesHelper::getNonInternalProperties($entity->getTypedData());
|
||||
// If the fields to use were specified, only output those field values.
|
||||
if (isset($context['included_fields'])) {
|
||||
$field_items = [];
|
||||
foreach ($context['included_fields'] as $field_name) {
|
||||
$field_items[] = $entity->get($field_name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$field_items = $entity->getFields();
|
||||
$field_items = array_intersect_key($field_items, array_flip($context['included_fields']));
|
||||
}
|
||||
foreach ($field_items as $field) {
|
||||
// Continue if the current user does not have access to view this field.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Drupal\hal\Normalizer;
|
||||
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\Core\TypedData\TypedDataInternalPropertiesHelper;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
@@ -91,7 +92,7 @@ class FieldItemNormalizer extends NormalizerBase {
|
||||
// We normalize each individual property, so each can do their own casting,
|
||||
// if needed.
|
||||
/** @var \Drupal\Core\TypedData\TypedDataInterface $property */
|
||||
foreach ($field_item as $property_name => $property) {
|
||||
foreach (TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item) as $property_name => $property) {
|
||||
$normalized[$property_name] = $this->serializer->normalize($property, $format, $context);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Drupal\hal\Normalizer;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\hal\LinkManager\LinkManagerInterface;
|
||||
@@ -9,6 +10,8 @@ use GuzzleHttp\ClientInterface;
|
||||
|
||||
/**
|
||||
* Converts the Drupal entity object structure to a HAL array structure.
|
||||
*
|
||||
* @deprecated in Drupal 8.5.0, to be removed before Drupal 9.0.0.
|
||||
*/
|
||||
class FileEntityNormalizer extends ContentEntityNormalizer {
|
||||
|
||||
@@ -26,6 +29,13 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
|
||||
*/
|
||||
protected $httpClient;
|
||||
|
||||
/**
|
||||
* The HAL settings config.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ImmutableConfig
|
||||
*/
|
||||
protected $halSettings;
|
||||
|
||||
/**
|
||||
* Constructs a FileEntityNormalizer object.
|
||||
*
|
||||
@@ -37,11 +47,14 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
|
||||
* The hypermedia link manager.
|
||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
||||
* The module handler.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, ClientInterface $http_client, LinkManagerInterface $link_manager, ModuleHandlerInterface $module_handler) {
|
||||
public function __construct(EntityManagerInterface $entity_manager, ClientInterface $http_client, LinkManagerInterface $link_manager, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
|
||||
parent::__construct($link_manager, $entity_manager, $module_handler);
|
||||
|
||||
$this->httpClient = $http_client;
|
||||
$this->halSettings = $config_factory->get('hal.settings');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,8 +62,13 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
|
||||
*/
|
||||
public function normalize($entity, $format = NULL, array $context = []) {
|
||||
$data = parent::normalize($entity, $format, $context);
|
||||
// Replace the file url with a full url for the file.
|
||||
$data['uri'][0]['value'] = $this->getEntityUri($entity);
|
||||
|
||||
$this->addCacheableDependency($context, $this->halSettings);
|
||||
|
||||
if ($this->halSettings->get('bc_file_uri_as_url_normalizer')) {
|
||||
// Replace the file url with a full url for the file.
|
||||
$data['uri'][0]['value'] = $this->getEntityUri($entity);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user