Unverified Commit 29cb1c03 authored by e0ipso's avatar e0ipso Committed by Mateu Aguiló Bosch

Issue #3020237 by ndobromirov, rhristov, e0ipso, vtcore, daniel.nitsche,...

Issue #3020237 by ndobromirov, rhristov, e0ipso, vtcore, daniel.nitsche, cspitzlay: [Regression] Broken with latest jsonapi 2.0-rc3
parent 0e7ca576
......@@ -4,5 +4,5 @@ description: Builds on top of JSON API to deliver extra functionality.
core: 8.x
package: Web services
dependencies:
- jsonapi (>= 8.x-2.0-beta1)
- jsonapi_extras
- jsonapi:jsonapi
- jsonapi_extras:jsonapi_extras
......@@ -48,27 +48,6 @@ class JsonapiResourceConfig extends ConfigEntityBase {
*/
protected $id;
/**
* The path for the resource.
*
* @var string
*/
protected $path;
/**
* The type for the resource.
*
* @var string
*/
protected $resourceType;
/**
* Resource fields.
*
* @var array
*/
protected $resourceFields = [];
/**
* {@inheritdoc}
*/
......
......@@ -172,10 +172,7 @@ class JsonapiResourceConfigForm extends EntityForm {
// Log the exception and continue.
watchdog_exception('jsonapi_extras', $exception);
}
$form['id'] = [
'#type' => 'hidden',
'#value' => sprintf('%s--%s', $entity_type_id, $bundle),
];
$form['id'] = ['#type' => 'hidden', '#value' => $resource_config_id];
}
return $form;
......@@ -386,7 +383,8 @@ class JsonapiResourceConfigForm extends EntityForm {
* @throws \Drupal\Component\Plugin\Exception\PluginException
*/
protected function buildOverridesField($field_name, JsonapiResourceConfig $entity) {
$resource_fields = array_filter($entity->get('resourceFields'), function (array $resource_field) use ($field_name) {
$rfs = $entity->get('resourceFields') ?: [];
$resource_fields = array_filter($rfs, function (array $resource_field) use ($field_name) {
return $resource_field['fieldName'] == $field_name;
});
$resource_field = array_shift($resource_fields);
......
......@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository;
use Drupal\jsonapi_extras\ResourceType\NullJsonapiResourceConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -173,7 +174,7 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder {
/** @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig $resource_config */
$resource_config = $resource_type->getJsonapiResourceConfig();
if ($resource_config->id()) {
if (!$resource_config instanceof NullJsonapiResourceConfig) {
$row['state']['#value'] = $this->t('Overwritten');
$row['state']['#attributes']['class'][] = 'label--overwritten';
$row['operations']['#links'] = $this->getDefaultOperations($resource_config);
......
......@@ -35,10 +35,10 @@ trait EntityNormalizerTrait {
// Translate the public fields into the entity fields.
foreach ($data as $public_field_name => $field_value) {
// Skip any disabled field.
if (!$resource_type->isFieldEnabled($public_field_name)) {
$internal_name = $resource_type->getInternalName($public_field_name);
if (!$resource_type->isFieldEnabled($internal_name)) {
continue;
}
$internal_name = $resource_type->getInternalName($public_field_name);
$enhancer = $resource_type->getFieldEnhancer($public_field_name, 'publicName');
if (isset($field_storage_definitions[$internal_name])) {
......@@ -66,7 +66,7 @@ trait EntityNormalizerTrait {
$data_internal[$internal_name] = $field_value;
}
return $data_internal;
return parent::prepareInput($data_internal, $resource_type, $format, $context);
}
/**
......
......@@ -9,12 +9,13 @@ use Drupal\jsonapi\Normalizer\NormalizerBase;
use Drupal\jsonapi\Normalizer\FieldItemNormalizer as JsonapiFieldItemNormalizer;
use Drupal\jsonapi\Normalizer\Value\FieldItemNormalizerValue;
use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
/**
* Converts the Drupal field structure to a JSON:API array structure.
*/
class FieldItemNormalizer extends NormalizerBase {
class FieldItemNormalizer extends NormalizerBase implements DenormalizerInterface {
/**
* The interface or class that this Normalizer supports.
......@@ -80,6 +81,13 @@ class FieldItemNormalizer extends NormalizerBase {
return $normalized_output;
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
return $this->subject->denormalize($data, $class, $format, $context);
}
/**
* {@inheritdoc}
*/
......
......@@ -152,14 +152,18 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
* The configuration entity for the resource type.
*/
protected function getResourceConfig($resource_config_id) {
$null_resource = new NullJsonapiResourceConfig(
['id' => $resource_config_id],
'jsonapi_resource_config'
);
try {
$resource_configs = $this->getResourceConfigs();
return isset($resource_configs[$resource_config_id]) ?
$resource_configs[$resource_config_id] :
new NullJsonapiResourceConfig([], '');
$null_resource;
}
catch (PluginException $e) {
return new NullJsonapiResourceConfig([], '');
return $null_resource;
}
}
......@@ -233,9 +237,6 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
protected function overrideFieldMapping(JsonapiResourceConfig $resource_config) {
if ($resource_config instanceof NullJsonapiResourceConfig) {
return [];
}
// This is not ideal, but we cannot load the resource type to get the entity
// type object. That is because this is used during the creation of the
// ResourceType.
......
......@@ -23,11 +23,4 @@ class NullJsonapiResourceConfig extends JsonapiResourceConfig {
return __CLASS__;
}
/**
* {@inheritdoc}
*/
public function getEntityType() {
return NULL;
}
}
......@@ -258,7 +258,7 @@ class JsonApiExtrasFunctionalTest extends JsonApiFunctionalTestBase {
];
$response = $this->request('POST', $collection_url, [
'body' => Json::encode($body),
'auth' => [$this->user->getUsername(), $this->user->pass_raw],
'auth' => [$this->user->getAccountName(), $this->user->pass_raw],
'headers' => ['Content-Type' => 'application/vnd.api+json'],
]);
$created_response = Json::decode((string) $response->getBody());
......@@ -280,7 +280,7 @@ class JsonApiExtrasFunctionalTest extends JsonApiFunctionalTestBase {
];
$response = $this->request('POST', $relationships_url, [
'body' => Json::encode($body),
'auth' => [$this->user->getUsername(), $this->user->pass_raw],
'auth' => [$this->user->getAccountName(), $this->user->pass_raw],
'headers' => ['Content-Type' => 'application/vnd.api+json'],
]);
$created_response = Json::decode((string) $response->getBody());
......@@ -291,12 +291,13 @@ class JsonApiExtrasFunctionalTest extends JsonApiFunctionalTestBase {
* Creates the JSON:API Resource Config entities to override the resources.
*/
protected static function overrideResources() {
// Disable the user resource.
// Disable the taxonomy_vocabulary resource.
JsonapiResourceConfig::create([
'id' => 'taxonomy_vocabulary--taxonomy_vocabulary',
'disabled' => TRUE,
'path' => 'taxonomy_vocabulary/taxonomy_vocabulary',
'resourceType' => 'taxonomy_vocabulary--taxonomy_vocabulary',
'resourceFields' => [],
])->save();
// Override paths and fields in the articles resource.
JsonapiResourceConfig::create([
......
......@@ -178,17 +178,17 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
[
[
'type' => 'taxonomy_term--tags',
'id' => $this->term1->uuid(),
'attributes' => [
'tid' => (int) $this->term1->id(),
'uuid' => $this->term1->uuid(),
'drupal_internal__tid' => (int) $this->term1->id(),
'name' => $this->term1->label(),
],
],
[
'type' => 'taxonomy_term--tags',
'id' => $this->term2->uuid(),
'attributes' => [
'tid' => (int) $this->term2->id(),
'uuid' => $this->term2->uuid(),
'drupal_internal__tid' => (int) $this->term2->id(),
'name' => $this->term2->label(),
],
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment