Skip to content
Snippets Groups Projects
Unverified Commit cc7daf4b authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Issue #3018067: Ensure the entity bundle is provided to the resource repository

parent 11c96cc7
Branches
Tags 8.x-2.13
No related merge requests found
......@@ -35,7 +35,10 @@ class SchemaFieldDefinitionNormalizer extends SchemataJsonSchemaFieldDefinitionN
$normalized = parent::normalize($entity, $format, $context);
// Load the resource type for this entity type and bundle.
$resource_type = $this->resourceTypeRepository->get($context['entityTypeId'], $context['bundleId']);
$bundle = empty($context['bundleId'])
? $context['entityTypeId']
: $context['bundleId'];
$resource_type = $this->resourceTypeRepository->get($context['entityTypeId'], $bundle);
if (!$resource_type || !$resource_type instanceof ConfigurableResourceType) {
return $normalized;
......
......@@ -2,6 +2,7 @@
namespace Drupal\jsonapi_extras\Normalizer;
use Drupal\Component\Utility\NestedArray;
use Drupal\schemata_json_schema\Normalizer\jsonapi\SchemataSchemaNormalizer as SchemataJsonSchemaSchemataSchemaNormalizer;
use Drupal\jsonapi\ResourceType\ResourceTypeRepository;
......@@ -34,7 +35,12 @@ class SchemataSchemaNormalizer extends SchemataJsonSchemaSchemataSchemaNormalize
$normalized = parent::normalize($entity, $format, $context);
// Load the resource type for this entity type and bundle.
$resource_type = $this->resourceTypeRepository->get($entity->getEntityTypeId(), $entity->getBundleId());
$bundle = $entity->getBundleId();
$bundle = $bundle ?: $entity->getEntityTypeId();
$resource_type = $this->resourceTypeRepository->get(
$entity->getEntityTypeId(),
$bundle
);
if (!$resource_type) {
return $normalized;
......@@ -47,8 +53,9 @@ class SchemataSchemaNormalizer extends SchemataJsonSchemaSchemataSchemaNormalize
$root[$property_type]['required'] = [];
}
$required_fields = [];
foreach ($root[$property_type]['properties'] as $fieldname => $schema) {
$properties = &$root[$property_type]['properties'];
$properties = NestedArray::getValue($root, [$property_type, 'properties']);
$properties = $properties ?: [];
foreach ($properties as $fieldname => $schema) {
unset($properties[$fieldname]);
if (!$resource_type->isFieldEnabled($fieldname)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment