updated core to 8.6.1 via composer

This commit is contained in:
2018-09-12 13:58:26 +02:00
parent a9a219f2ed
commit ea56b9fba3
4443 changed files with 112098 additions and 40708 deletions
@@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
class RelationLinkManager extends LinkManagerBase implements RelationLinkManagerInterface {
/**
* @var \Drupal\Core\Cache\CacheBackendInterface;
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
@@ -70,10 +70,7 @@ class RelationLinkManager extends LinkManagerBase implements RelationLinkManager
// override the RelationLinkManager class/service to return the desired URL.
$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
// @see https://www.drupal.org/node/2830467
$this->moduleHandler->alter('rest_relation_uri', $uri, $context);
$this->moduleHandler->alterDeprecated('This hook is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Implement hook_hal_relation_uri_alter() instead.', 'rest_relation_uri', $uri, $context);
return $uri;
}
@@ -14,7 +14,7 @@ class TypeLinkManager extends LinkManagerBase implements TypeLinkManagerInterfac
/**
* Injected cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface;
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
@@ -71,10 +71,7 @@ class TypeLinkManager extends LinkManagerBase implements TypeLinkManagerInterfac
// TypeLinkManager class/service to return the desired URL.
$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
// @see https://www.drupal.org/node/2830467
$this->moduleHandler->alter('rest_type_uri', $uri, $context);
$this->moduleHandler->alterDeprecated('This hook is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0. Implement hook_hal_type_uri_alter() instead.', 'rest_type_uri', $uri, $context);
return $uri;
}
@@ -2,16 +2,22 @@
namespace Drupal\hal\Normalizer;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\hal\LinkManager\LinkManagerInterface;
use Drupal\serialization\EntityResolver\EntityResolverInterface;
use Drupal\serialization\EntityResolver\UuidReferenceInterface;
use Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizerTrait;
/**
* Converts the Drupal entity reference item object to HAL array structure.
*/
class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidReferenceInterface {
use EntityReferenceFieldItemNormalizerTrait;
/**
* The interface or class that this Normalizer supports.
*
@@ -33,6 +39,13 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
*/
protected $entityResolver;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs an EntityReferenceItemNormalizer object.
*
@@ -40,25 +53,28 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
* The hypermedia link manager.
* @param \Drupal\serialization\EntityResolver\EntityResolverInterface $entity_Resolver
* The entity resolver.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entity_type_manager
* The entity type manager.
*/
public function __construct(LinkManagerInterface $link_manager, EntityResolverInterface $entity_Resolver) {
public function __construct(LinkManagerInterface $link_manager, EntityResolverInterface $entity_Resolver, EntityTypeManagerInterface $entity_type_manager = NULL) {
$this->linkManager = $link_manager;
$this->entityResolver = $entity_Resolver;
$this->entityTypeManager = $entity_type_manager ?: \Drupal::service('entity_type.manager');
}
/**
* {@inheritdoc}
*/
public function normalize($field_item, $format = NULL, array $context = []) {
/** @var $field_item \Drupal\Core\Field\FieldItemInterface */
$target_entity = $field_item->get('entity')->getValue();
// If this is not a content entity, let the parent implementation handle it,
// only content entities are supported as embedded resources.
if (!($target_entity instanceof FieldableEntityInterface)) {
// If this is not a fieldable entity, let the parent implementation handle
// it, only fieldable entities are supported as embedded resources.
if (!$this->targetEntityIsFieldable($field_item)) {
return parent::normalize($field_item, $format, $context);
}
/** @var $field_item \Drupal\Core\Field\FieldItemInterface */
$target_entity = $field_item->get('entity')->getValue();
// If the parent entity passed in a langcode, unset it before normalizing
// the target entity. Otherwise, untranslatable fields of the target entity
// will include the langcode.
@@ -91,6 +107,39 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
];
}
/**
* Checks whether the referenced entity is of a fieldable entity type.
*
* @param \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $item
* The reference field item whose target entity needs to be checked.
*
* @return bool
* TRUE when the referenced entity is of a fieldable entity type.
*/
protected function targetEntityIsFieldable(EntityReferenceItem $item) {
$target_entity = $item->get('entity')->getValue();
if ($target_entity !== NULL) {
return $target_entity instanceof FieldableEntityInterface;
}
$referencing_entity = $item->getEntity();
$target_entity_type_id = $item->getFieldDefinition()->getSetting('target_type');
// If the entity type is the same as the parent, we can check that. This is
// just a shortcut to avoid getting the entity type defintition and checking
// the class.
if ($target_entity_type_id === $referencing_entity->getEntityTypeId()) {
return $referencing_entity instanceof FieldableEntityInterface;
}
// Otherwise, we need to get the class for the type.
$target_entity_type = $this->entityTypeManager->getDefinition($target_entity_type_id);
$target_entity_type_class = $target_entity_type->getClass();
return is_a($target_entity_type_class, FieldableEntityInterface::class, TRUE);
}
/**
* {@inheritdoc}
*/
@@ -100,11 +149,26 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR
$target_type = $field_definition->getSetting('target_type');
$id = $this->entityResolver->resolve($this, $data, $target_type);
if (isset($id)) {
return ['target_id' => $id];
return ['target_id' => $id] + array_intersect_key($data, $field_item->getProperties());
}
return NULL;
}
/**
* {@inheritdoc}
*/
protected function normalizedFieldValues(FieldItemInterface $field_item, $format, array $context) {
// Normalize root reference values here so we don't need to deal with hal's
// nested data structure for field items. This will be called from
// \Drupal\hal\Normalizer\FieldItemNormalizer::normalize. Which will only
// be called from this class for entities that are not fieldable.
$normalized = parent::normalizedFieldValues($field_item, $format, $context);
$this->normalizeRootReferenceValue($normalized, $field_item);
return $normalized;
}
/**
* {@inheritdoc}
*/
@@ -92,7 +92,10 @@ 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 (TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item) as $property_name => $property) {
$field_properties = !empty($field_item->getProperties(TRUE))
? TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item)
: $field_item->getValue();
foreach ($field_properties as $property_name => $property) {
$normalized[$property_name] = $this->serializer->normalize($property, $format, $context);
}
@@ -6,7 +6,6 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\hal\LinkManager\LinkManagerInterface;
use GuzzleHttp\ClientInterface;
/**
* Converts the Drupal entity object structure to a HAL array structure.
@@ -41,8 +40,6 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \GuzzleHttp\ClientInterface $http_client
* The HTTP Client.
* @param \Drupal\hal\LinkManager\LinkManagerInterface $link_manager
* The hypermedia link manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
@@ -50,10 +47,9 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
* @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, ConfigFactoryInterface $config_factory) {
public function __construct(EntityManagerInterface $entity_manager, 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');
}
@@ -73,16 +69,4 @@ class FileEntityNormalizer extends ContentEntityNormalizer {
return $data;
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
$file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody();
$path = 'temporary://' . drupal_basename($data['uri'][0]['value']);
$data['uri'] = file_unmanaged_save_data($file_data, $path);
return $this->entityManager->getStorage('file')->create($data);
}
}