Commit 68ceb417 authored by Luhur Abdi Rizal's avatar Luhur Abdi Rizal
Browse files

Issue #3266740 by el7cosmos: Move jsonapi, media, and webform event constants to a class

parent 5602d055
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\hook_event_dispatcher\Event\AccessEventInterface;
use Drupal\hook_event_dispatcher\Event\AccessEventTrait;
use Drupal\hook_event_dispatcher\Event\EventInterface;
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
use Drupal\jsonapi_event_dispatcher\JsonApiHookEvents;

/**
 * Class JsonApiEntityFieldFilterAccessEvent.
@@ -51,7 +51,7 @@ class JsonApiEntityFieldFilterAccessEvent extends Event implements EventInterfac
   * {@inheritdoc}
   */
  public function getDispatcherType(): string {
    return HookEventDispatcherInterface::JSONAPI_ENTITY_FIELD_FILTER_ACCESS;
    return JsonApiHookEvents::JSONAPI_ENTITY_FIELD_FILTER_ACCESS;
  }

}
+2 −2
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\hook_event_dispatcher\Event\EventInterface;
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
use Drupal\jsonapi_event_dispatcher\JsonApiHookEvents;

/**
 * Class JsonapiEntityFilterAccessEvent.
@@ -94,7 +94,7 @@ class JsonApiEntityFilterAccessEvent extends Event implements EventInterface {
   * {@inheritdoc}
   */
  public function getDispatcherType(): string {
    return HookEventDispatcherInterface::JSONAPI_ENTITY_FILTER_ACCESS;
    return JsonApiHookEvents::JSONAPI_ENTITY_FILTER_ACCESS;
  }

}
+38 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\jsonapi_event_dispatcher;

use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;

/**
 * Defines events for jsonapi hooks.
 */
final class JsonApiHookEvents {

  /**
   * Controls access when filtering by entity data via JSON:API.
   *
   * @Event
   *
   * @see \Drupal\jsonapi_event_dispatcher\Event\JsonApiEntityFilterAccessEvent
   * @see jsonapi_event_dispatcher_jsonapi_entity_filter_access()
   * @see hook_jsonapi_entity_filter_access()
   *
   * @var string
   */
  public const JSONAPI_ENTITY_FILTER_ACCESS = HookEventDispatcherInterface::PREFIX . 'jsonapi.entity_filter_access';

  /**
   * Restricts filtering access to the given field.
   *
   * @Event
   *
   * @see \Drupal\jsonapi_event_dispatcher\Event\JsonApiEntityFieldFilterAccessEvent
   * @see jsonapi_event_dispatcher_jsonapi_entity_field_filter_access()
   * @see hook_jsonapi_entity_field_filter_access()
   *
   * @var string
   */
  public const JSONAPI_ENTITY_FIELD_FILTER_ACCESS = HookEventDispatcherInterface::PREFIX . 'jsonapi.entity_field_filter_access';

}
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@
namespace Drupal\Tests\jsonapi_event_dispatcher\Kernel;

use Drupal\Core\Access\AccessResult;
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
use Drupal\jsonapi_event_dispatcher\Event\JsonApiEntityFieldFilterAccessEvent;
use Drupal\jsonapi_event_dispatcher\JsonApiHookEvents;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\hook_event_dispatcher\Kernel\ListenerTrait;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -80,7 +80,7 @@ class JsonApiEntityFieldFilterAccessEventTest extends KernelTestBase {
      $this->expectException($exception);
    }

    $this->listen(HookEventDispatcherInterface::JSONAPI_ENTITY_FIELD_FILTER_ACCESS, 'onJsonapiEntityFieldFilterAccess');
    $this->listen(JsonApiHookEvents::JSONAPI_ENTITY_FIELD_FILTER_ACCESS, 'onJsonapiEntityFieldFilterAccess');

    $repository = $this->container->get('jsonapi.resource_type.repository');
    $path = $this->container->get('jsonapi.field_resolver')->resolveInternalEntityQueryPath($repository->get('entity_test', 'entity_test'), $fieldName);
+2 −2
Original line number Diff line number Diff line
@@ -4,11 +4,11 @@ namespace Drupal\Tests\jsonapi_event_dispatcher\Kernel;

use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\hook_event_dispatcher\HookEventDispatcherInterface;
use Drupal\jsonapi\JsonApiResource\Data;
use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel;
use Drupal\jsonapi\ResourceType\ResourceType;
use Drupal\jsonapi_event_dispatcher\Event\JsonApiEntityFilterAccessEvent;
use Drupal\jsonapi_event_dispatcher\JsonApiHookEvents;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\hook_event_dispatcher\Kernel\ListenerTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
@@ -49,7 +49,7 @@ class JsonApiEntityFilterAccessEventTest extends KernelTestBase {
   * @throws \Exception
   */
  public function testJsonapiEntityFilterAccessEvent(): void {
    $this->listen(HookEventDispatcherInterface::JSONAPI_ENTITY_FILTER_ACCESS, 'onJsonapiEntityFilterAccess');
    $this->listen(JsonApiHookEvents::JSONAPI_ENTITY_FILTER_ACCESS, 'onJsonapiEntityFilterAccess');

    $this->setUpCurrentUser([], ['view test entity']);
    $entity = $this->createEntity();
Loading