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

Issue #3013544 by e0ipso, benjifisher, kil, xiukun.zhou, superbiche,...

Issue #3013544 by e0ipso, benjifisher, kil, xiukun.zhou, superbiche, labboy0276, TwoD, eojthebrave, jebschiefer, ashutoshsngh, el1_1el, gun_dose, marc.groth: Update to 2.11 is broken
parent 39f1e14a
...@@ -48,27 +48,6 @@ class JsonapiResourceConfig extends ConfigEntityBase { ...@@ -48,27 +48,6 @@ class JsonapiResourceConfig extends ConfigEntityBase {
*/ */
protected $id; 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} * {@inheritdoc}
*/ */
......
...@@ -161,10 +161,7 @@ class JsonapiResourceConfigForm extends EntityForm { ...@@ -161,10 +161,7 @@ class JsonapiResourceConfigForm extends EntityForm {
return $form; return $form;
} }
$form['bundle_wrapper']['fields_wrapper'] = $this->buildOverridesForm($resource_type, $entity); $form['bundle_wrapper']['fields_wrapper'] = $this->buildOverridesForm($resource_type, $entity);
$form['id'] = [ $form['id'] = ['#type' => 'hidden', '#value' => $resource_config_id];
'#type' => 'hidden',
'#value' => sprintf('%s--%s', $entity_type_id, $bundle),
];
} }
return $form; return $form;
...@@ -318,7 +315,7 @@ class JsonapiResourceConfigForm extends EntityForm { ...@@ -318,7 +315,7 @@ class JsonapiResourceConfigForm extends EntityForm {
'disabled' => $this->t('Disabled'), 'disabled' => $this->t('Disabled'),
'fieldName' => $this->t('Field name'), 'fieldName' => $this->t('Field name'),
'publicName' => $this->t('Alias'), 'publicName' => $this->t('Alias'),
'advancedOptions' => $this->t(''), 'advancedOptions' => '',
], ],
'#empty' => $this->t('No fields available.'), '#empty' => $this->t('No fields available.'),
'#states' => [ '#states' => [
...@@ -328,7 +325,7 @@ class JsonapiResourceConfigForm extends EntityForm { ...@@ -328,7 +325,7 @@ class JsonapiResourceConfigForm extends EntityForm {
], ],
'#attached' => [ '#attached' => [
'library' => [ 'library' => [
'jsonapi_extras/expandable_rows_table', 'jsonapi_extras/expandable_rows_table',
], ],
], ],
]; ];
...@@ -368,7 +365,8 @@ class JsonapiResourceConfigForm extends EntityForm { ...@@ -368,7 +365,8 @@ class JsonapiResourceConfigForm extends EntityForm {
* The partial form. * The partial form.
*/ */
protected function buildOverridesField($field_name, JsonapiResourceConfig $entity) { 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; return $resource_field['fieldName'] == $field_name;
}); });
$resource_field = array_shift($resource_fields); $resource_field = array_shift($resource_fields);
...@@ -403,7 +401,7 @@ class JsonapiResourceConfigForm extends EntityForm { ...@@ -403,7 +401,7 @@ class JsonapiResourceConfigForm extends EntityForm {
$overrides_form['advancedOptionsIcon'] = [ $overrides_form['advancedOptionsIcon'] = [
// Here we are just printing an arrow. // Here we are just printing an arrow.
'#markup' => '↳' '#markup' => '↳',
]; ];
$overrides_form['enhancer_label'] = [ $overrides_form['enhancer_label'] = [
...@@ -480,7 +478,8 @@ class JsonapiResourceConfigForm extends EntityForm { ...@@ -480,7 +478,8 @@ class JsonapiResourceConfigForm extends EntityForm {
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function actionsElement(array $form, FormStateInterface $form_state) { protected function actionsElement(array $form, FormStateInterface $form_state) {
// We want to display "Revert" instead of "Delete" on the Resource Config Form. // We want to display "Revert" instead of "Delete" on the Resource Config
// Form.
$element = parent::actionsElement($form, $form_state); $element = parent::actionsElement($form, $form_state);
if (isset($element['delete'])) { if (isset($element['delete'])) {
$element['delete']['#title'] = $this->t('Revert'); $element['delete']['#title'] = $this->t('Revert');
......
...@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface; ...@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository;
use Drupal\jsonapi_extras\ResourceType\NullJsonapiResourceConfig;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -192,7 +193,7 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { ...@@ -192,7 +193,7 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder {
/** @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig $resource_config */ /** @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig $resource_config */
$resource_config = $resource_type->getJsonapiResourceConfig(); $resource_config = $resource_type->getJsonapiResourceConfig();
if ($resource_config->id()) { if (!$resource_config instanceof NullJsonapiResourceConfig) {
$row['state']['#value'] = $this->t('Overwritten'); $row['state']['#value'] = $this->t('Overwritten');
$row['state']['#attributes']['class'][] = 'label--overwritten'; $row['state']['#attributes']['class'][] = 'label--overwritten';
$row['operations']['#links'] = $this->getDefaultOperations($resource_config); $row['operations']['#links'] = $this->getDefaultOperations($resource_config);
......
...@@ -39,10 +39,10 @@ trait EntityNormalizerTrait { ...@@ -39,10 +39,10 @@ trait EntityNormalizerTrait {
// Translate the public fields into the entity fields. // Translate the public fields into the entity fields.
foreach ($data as $public_field_name => $field_value) { foreach ($data as $public_field_name => $field_value) {
// Skip any disabled field. // 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; continue;
} }
$internal_name = $resource_type->getInternalName($public_field_name);
$enhancer = $resource_type->getFieldEnhancer($public_field_name, 'publicName'); $enhancer = $resource_type->getFieldEnhancer($public_field_name, 'publicName');
if (isset($field_storage_definitions[$internal_name])) { if (isset($field_storage_definitions[$internal_name])) {
...@@ -70,7 +70,7 @@ trait EntityNormalizerTrait { ...@@ -70,7 +70,7 @@ trait EntityNormalizerTrait {
$data_internal[$internal_name] = $field_value; $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; ...@@ -9,12 +9,13 @@ use Drupal\jsonapi\Normalizer\NormalizerBase;
use Drupal\jsonapi\Normalizer\FieldItemNormalizer as JsonapiFieldItemNormalizer; use Drupal\jsonapi\Normalizer\FieldItemNormalizer as JsonapiFieldItemNormalizer;
use Drupal\jsonapi\Normalizer\Value\FieldItemNormalizerValue; use Drupal\jsonapi\Normalizer\Value\FieldItemNormalizerValue;
use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager; use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Serializer\SerializerInterface;
/** /**
* Converts the Drupal field structure to a JSON API array structure. * 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. * The interface or class that this Normalizer supports.
...@@ -80,6 +81,13 @@ class FieldItemNormalizer extends NormalizerBase { ...@@ -80,6 +81,13 @@ class FieldItemNormalizer extends NormalizerBase {
return $normalized_output; return $normalized_output;
} }
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
return $this->subject->denormalize($data, $class, $format, $context);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -215,14 +215,18 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository { ...@@ -215,14 +215,18 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
* The configuration entity for the resource type. * The configuration entity for the resource type.
*/ */
protected function getResourceConfig($resource_config_id) { protected function getResourceConfig($resource_config_id) {
$null_resource = new NullJsonapiResourceConfig(
['id' => $resource_config_id],
'jsonapi_resource_config'
);
try { try {
$resource_configs = $this->getResourceConfigs(); $resource_configs = $this->getResourceConfigs();
return isset($resource_configs[$resource_config_id]) ? return isset($resource_configs[$resource_config_id]) ?
$resource_configs[$resource_config_id] : $resource_configs[$resource_config_id] :
new NullJsonapiResourceConfig([], ''); $null_resource;
} }
catch (PluginException $e) { catch (PluginException $e) {
return new NullJsonapiResourceConfig([], ''); return $null_resource;
} }
} }
......
...@@ -23,11 +23,4 @@ class NullJsonapiResourceConfig extends JsonapiResourceConfig { ...@@ -23,11 +23,4 @@ class NullJsonapiResourceConfig extends JsonapiResourceConfig {
return __CLASS__; return __CLASS__;
} }
/**
* {@inheritdoc}
*/
public function getEntityType() {
return NULL;
}
} }
...@@ -76,7 +76,11 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase { ...@@ -76,7 +76,11 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
static::overrideResources(); static::overrideResources();
$this->resetAll(); $this->resetAll();
$role = $this->user->get('roles')[0]->entity; $role = $this->user->get('roles')[0]->entity;
$this->grantPermissions($role, ['administer nodes', 'administer site configuration']); $this->grantPermissions($role, [
'administer nodes',
'administer site configuration',
'access user profiles',
]);
} }
/** /**
...@@ -264,7 +268,7 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase { ...@@ -264,7 +268,7 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
]; ];
$response = $this->request('POST', $collection_url, [ $response = $this->request('POST', $collection_url, [
'body' => Json::encode($body), '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'], 'headers' => ['Content-Type' => 'application/vnd.api+json'],
]); ]);
$created_response = Json::decode((string) $response->getBody()); $created_response = Json::decode((string) $response->getBody());
...@@ -291,7 +295,7 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase { ...@@ -291,7 +295,7 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
]; ];
$response = $this->request('POST', $relationships_url, [ $response = $this->request('POST', $relationships_url, [
'body' => Json::encode($body), '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'], 'headers' => ['Content-Type' => 'application/vnd.api+json'],
]); ]);
$created_response = Json::decode((string) $response->getBody()); $created_response = Json::decode((string) $response->getBody());
...@@ -302,12 +306,13 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase { ...@@ -302,12 +306,13 @@ class JsonExtrasApiFunctionalTest extends JsonApiFunctionalTestBase {
* Creates the JSON API Resource Config entities to override the resources. * Creates the JSON API Resource Config entities to override the resources.
*/ */
protected static function overrideResources() { protected static function overrideResources() {
// Disable the user resource. // Disable the taxonomy_vocabulary resource.
JsonapiResourceConfig::create([ JsonapiResourceConfig::create([
'id' => 'taxonomy_vocabulary--taxonomy_vocabulary', 'id' => 'taxonomy_vocabulary--taxonomy_vocabulary',
'disabled' => TRUE, 'disabled' => TRUE,
'path' => 'taxonomy_vocabulary/taxonomy_vocabulary', 'path' => 'taxonomy_vocabulary/taxonomy_vocabulary',
'resourceType' => 'taxonomy_vocabulary--taxonomy_vocabulary', 'resourceType' => 'taxonomy_vocabulary--taxonomy_vocabulary',
'resourceFields' => [],
])->save(); ])->save();
// Override paths and fields in the articles resource. // Override paths and fields in the articles resource.
JsonapiResourceConfig::create([ JsonapiResourceConfig::create([
......
...@@ -75,7 +75,8 @@ class EntityResourceTest extends KernelTestBase { ...@@ -75,7 +75,8 @@ class EntityResourceTest extends KernelTestBase {
$this->container->get('jsonapi.resource_type.repository'), $this->container->get('jsonapi.resource_type.repository'),
$this->container->get('renderer'), $this->container->get('renderer'),
$this->container->get('entity.repository'), $this->container->get('entity.repository'),
$this->container->get('jsonapi.include_resolver') $this->container->get('jsonapi.include_resolver'),
$this->container->get('renderer')
); );
$response = $entity_resource->createIndividual($resource_type, $node_type, new Request()); $response = $entity_resource->createIndividual($resource_type, $node_type, new Request());
} }
...@@ -86,7 +87,8 @@ class EntityResourceTest extends KernelTestBase { ...@@ -86,7 +87,8 @@ class EntityResourceTest extends KernelTestBase {
$this->container->get('entity_field.manager'), $this->container->get('entity_field.manager'),
$this->container->get('plugin.manager.field.field_type'), $this->container->get('plugin.manager.field.field_type'),
$this->container->get('jsonapi.link_manager'), $this->container->get('jsonapi.link_manager'),
$this->container->get('jsonapi.resource_type.repository') $this->container->get('jsonapi.resource_type.repository'),
$this->container->get('renderer')
); );
$response = $entity_resource->createIndividual($node_type, new Request()); $response = $entity_resource->createIndividual($node_type, new Request());
} }
...@@ -141,7 +143,8 @@ class EntityResourceTest extends KernelTestBase { ...@@ -141,7 +143,8 @@ class EntityResourceTest extends KernelTestBase {
$this->container->get('jsonapi.resource_type.repository'), $this->container->get('jsonapi.resource_type.repository'),
$this->container->get('renderer'), $this->container->get('renderer'),
$this->container->get('entity.repository'), $this->container->get('entity.repository'),
$this->container->get('jsonapi.include_resolver') $this->container->get('jsonapi.include_resolver'),
$this->container->get('renderer')
); );
$response = $entity_resource->patchIndividual($resource_type, $node_type, $parsed_node_type, $request); $response = $entity_resource->patchIndividual($resource_type, $node_type, $parsed_node_type, $request);
} }
...@@ -152,7 +155,8 @@ class EntityResourceTest extends KernelTestBase { ...@@ -152,7 +155,8 @@ class EntityResourceTest extends KernelTestBase {
$this->container->get('entity_field.manager'), $this->container->get('entity_field.manager'),
$this->container->get('plugin.manager.field.field_type'), $this->container->get('plugin.manager.field.field_type'),
$this->container->get('jsonapi.link_manager'), $this->container->get('jsonapi.link_manager'),
$this->container->get('jsonapi.resource_type.repository') $this->container->get('jsonapi.resource_type.repository'),
$this->container->get('renderer')
); );
$response = $entity_resource->patchIndividual($node_type, $parsed_node_type, $request); $response = $entity_resource->patchIndividual($node_type, $parsed_node_type, $request);
} }
...@@ -233,7 +237,8 @@ class EntityResourceTest extends KernelTestBase { ...@@ -233,7 +237,8 @@ class EntityResourceTest extends KernelTestBase {
$this->container->get('jsonapi.resource_type.repository'), $this->container->get('jsonapi.resource_type.repository'),
$this->container->get('renderer'), $this->container->get('renderer'),
$this->container->get('entity.repository'), $this->container->get('entity.repository'),
$this->container->get('jsonapi.include_resolver') $this->container->get('jsonapi.include_resolver'),
$this->container->get('renderer')
); );
} }
...@@ -244,7 +249,8 @@ class EntityResourceTest extends KernelTestBase { ...@@ -244,7 +249,8 @@ class EntityResourceTest extends KernelTestBase {
$this->container->get('entity_field.manager'), $this->container->get('entity_field.manager'),
$this->container->get('plugin.manager.field.field_type'), $this->container->get('plugin.manager.field.field_type'),
$this->container->get('jsonapi.link_manager'), $this->container->get('jsonapi.link_manager'),
$this->container->get('jsonapi.resource_type.repository') $this->container->get('jsonapi.resource_type.repository'),
$this->container->get('renderer')
); );
} }
$response = $entity_resource->deleteIndividual($node_type, new Request()); $response = $entity_resource->deleteIndividual($node_type, new Request());
......
...@@ -172,6 +172,9 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase { ...@@ -172,6 +172,9 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
* @covers ::normalize * @covers ::normalize
*/ */
public function testSerialize() { public function testSerialize() {
$tid_public_name = ConfigurableResourceTypeRepository::isJsonApi2x()
? 'drupal_internal__tid'
: 'tid';
$entities = [ $entities = [
[ [
$this->node, $this->node,
...@@ -179,17 +182,17 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase { ...@@ -179,17 +182,17 @@ class EntityToJsonApiTest extends JsonapiKernelTestBase {
[ [
[ [
'type' => 'taxonomy_term--tags', 'type' => 'taxonomy_term--tags',
'id' => $this->term1->uuid(),
'attributes' => [ 'attributes' => [
'tid' => (int) $this->term1->id(), $tid_public_name => (int) $this->term1->id(),
'uuid' => $this->term1->uuid(),
'name' => $this->term1->label(), 'name' => $this->term1->label(),
], ],
], ],
[ [
'type' => 'taxonomy_term--tags', 'type' => 'taxonomy_term--tags',
'id' => $this->term2->uuid(),
'attributes' => [ 'attributes' => [
'tid' => (int) $this->term2->id(), $tid_public_name => (int) $this->term2->id(),
'uuid' => $this->term2->uuid(),
'name' => $this->term2->label(), '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