Skip to content
Snippets Groups Projects
Commit a38e80b4 authored by Taras Kravchuk's avatar Taras Kravchuk
Browse files

Merge branch '3438947-the-included-array' into '2.x'

Issue #3438947 by _tarik_: Created trait that provides methods overrides,...

See merge request !10
parents a6c63234 6b1a6c92
No related branches found
No related tags found
No related merge requests found
Pipeline #138920 skipped
<?php
namespace Drupal\jsonapi_links\Controller;
use Drupal\jsonapi\Controller\EntityResource;
/**
* Overrides EntityResource JSON API.
*
* All code bellow is copied form EntityAccessChecker and required
* only to replace ResourceObject.
*/
class JsonApiEntityResource extends EntityResource {
use MethodOverrideTrait;
}
<?php
namespace Drupal\jsonapi_links\Controller;
// This controller is implemented by jsonapi_extras,
// so we need to inherit it instead of the default jsonapi controller.
use Drupal\jsonapi_defaults\Controller\EntityResource;
/**
* Overrides EntityResource JSON API.
*
* All code bellow is copied form EntityAccessChecker and required
* only to replace ResourceObject.
*/
class JsonApiExtrasEntityResource extends EntityResource {
use MethodOverrideTrait;
}
......@@ -9,13 +9,13 @@ use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\RevisionableEntityBundleInterface;
use Drupal\Core\Entity\RevisionableInterface;
use Drupal\Core\Entity\RevisionLogInterface;
use Drupal\jsonapi\Controller\EntityResource as JsonapiEntityResource;
use Drupal\jsonapi\Exception\EntityAccessDeniedHttpException;
use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel;
use Drupal\jsonapi\JsonApiResource\Relationship;
use Drupal\jsonapi\JsonApiResource\ResourceObjectData;
use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\jsonapi\ResourceType\ResourceTypeField;
// jsonapi_links: changed the namespace for ResourceObject.
use Drupal\jsonapi_links\JsonApiResource\ResourceObject;
use Symfony\Component\HttpFoundation\Request;
......@@ -23,12 +23,9 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
/**
* Overrides EntityResource JSON API.
*
* All code bellow is copied form EntityAccessChecker and required
* only to replace ResourceObject.
* Provides general methods overrides for the JSON:API module.
*/
class EntityResource extends JsonapiEntityResource {
trait MethodOverrideTrait {
/**
* {@inheritdoc}
......
......@@ -23,8 +23,14 @@ class JsonapiLinksServiceProvider extends ServiceProviderBase {
->setClass('Drupal\jsonapi\Normalizer\ImpostorFrom\jsonapi_links\ResourceObjectNormalizer');
// Overrides json api controller.
$container->getDefinition('jsonapi.entity_resource')
->setClass('Drupal\jsonapi_links\Controller\EntityResource');
if (isset($container_modules['jsonapi_defaults'])) {
$container->getDefinition('jsonapi.entity_resource')
->setClass('Drupal\jsonapi_links\Controller\JsonApiExtrasEntityResource');
}
else {
$container->getDefinition('jsonapi.entity_resource')
->setClass('Drupal\jsonapi_links\Controller\JsonApiEntityResource');
}
// Overrides json api access checker.
$container->getDefinition('jsonapi.entity_access_checker')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment