Skip to content
Snippets Groups Projects
Verified Commit d17c8302 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3420994 by kim.pepper: Convert RestResource plugin discovery to attributes

parent 636182e6
No related branches found
No related tags found
32 merge requests!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!9470[10.3.x-only-DO-NOT-MERGE]: #3331771 Fix file_get_contents(): Passing null to parameter,!8540Issue #3457061: Bootstrap Modal dialog Not closing after 10.3.0 Update,!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8373Issue #3427374 by danflanagan8, Vighneshh: taxonomy_tid ViewsArgumentDefault...,!7526Expose roles in response,!7352Draft: Resolve #3203489 "Set filename as",!6880Add @property to the DateTimeItem,!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2794Issue #3100732: Allow specifying `meta` data on JSON:API objects,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #108839 passed with warnings
Pipeline: drupal

#108844

    ...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
    namespace Drupal\dblog\Plugin\rest\resource; namespace Drupal\dblog\Plugin\rest\resource;
    use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\rest\Attribute\RestResource;
    use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\Plugin\ResourceBase;
    use Drupal\rest\ResourceResponse; use Drupal\rest\ResourceResponse;
    use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
    ...@@ -10,15 +12,14 @@ ...@@ -10,15 +12,14 @@
    /** /**
    * Provides a resource for database watchdog log entries. * Provides a resource for database watchdog log entries.
    *
    * @RestResource(
    * id = "dblog",
    * label = @Translation("Watchdog database log"),
    * uri_paths = {
    * "canonical" = "/dblog/{id}"
    * }
    * )
    */ */
    #[RestResource(
    id: "dblog",
    label: new TranslatableMarkup("Watchdog database log"),
    uri_paths: [
    "canonical" => "/dblog/{id}",
    ]
    )]
    class DbLogResource extends ResourceBase { class DbLogResource extends ResourceBase {
    /** /**
    ......
    ...@@ -12,12 +12,14 @@ ...@@ -12,12 +12,14 @@
    use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
    use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Lock\LockBackendInterface;
    use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\Core\Utility\Token; use Drupal\Core\Utility\Token;
    use Drupal\file\Entity\File; use Drupal\file\Entity\File;
    use Drupal\file\Upload\ContentDispositionFilenameParser; use Drupal\file\Upload\ContentDispositionFilenameParser;
    use Drupal\file\Upload\InputStreamFileWriterInterface; use Drupal\file\Upload\InputStreamFileWriterInterface;
    use Drupal\file\Validation\FileValidatorInterface; use Drupal\file\Validation\FileValidatorInterface;
    use Drupal\file\Validation\FileValidatorSettingsTrait; use Drupal\file\Validation\FileValidatorSettingsTrait;
    use Drupal\rest\Attribute\RestResource;
    use Drupal\rest\ModifiedResourceResponse; use Drupal\rest\ModifiedResourceResponse;
    use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\Plugin\ResourceBase;
    use Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait; use Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait;
    ...@@ -45,16 +47,15 @@ ...@@ -45,16 +47,15 @@
    * to be later moved when they are referenced from a file field. * to be later moved when they are referenced from a file field.
    * - Permission to upload a file can be determined by a users field level * - Permission to upload a file can be determined by a users field level
    * create access to the file field. * create access to the file field.
    *
    * @RestResource(
    * id = "file:upload",
    * label = @Translation("File Upload"),
    * serialization_class = "Drupal\file\Entity\File",
    * uri_paths = {
    * "create" = "/file/upload/{entity_type_id}/{bundle}/{field_name}"
    * }
    * )
    */ */
    #[RestResource(
    id: "file:upload",
    label: new TranslatableMarkup("File Upload"),
    serialization_class: File::class,
    uri_paths: [
    "create" => "/file/upload/{entity_type_id}/{bundle}/{field_name}",
    ]
    )]
    class FileUploadResource extends ResourceBase { class FileUploadResource extends ResourceBase {
    use FileValidatorSettingsTrait; use FileValidatorSettingsTrait;
    ......
    <?php
    declare(strict_types=1);
    namespace Drupal\rest\Attribute;
    use Drupal\Component\Plugin\Attribute\Plugin;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * Defines a REST resource attribute object.
    *
    * Plugin Namespace: Plugin\rest\resource
    *
    * For a working example, see \Drupal\dblog\Plugin\rest\resource\DbLogResource
    *
    * @see \Drupal\rest\Plugin\Type\ResourcePluginManager
    * @see \Drupal\rest\Plugin\ResourceBase
    * @see \Drupal\rest\Plugin\ResourceInterface
    * @see plugin_api
    *
    * @ingroup third_party
    */
    #[\Attribute(\Attribute::TARGET_CLASS)]
    class RestResource extends Plugin {
    /**
    * Constructs a RestResource attribute.
    *
    * @param string $id
    * The REST resource plugin ID.
    * @param \Drupal\Core\StringTranslation\TranslatableMarkup $label
    * The human-readable name of the REST resource plugin.
    * @param string|null $serialization_class
    * (optional) The serialization class to deserialize serialized data into.
    * @param string|null $deriver
    * (optional) The URI paths that this REST resource plugin provides.
    * - key: The link relation type plugin ID.
    * - value: The URL template.
    * @param array $uri_paths
    * (optional) The deriver class for the rest resource.
    *
    * @see \Symfony\Component\Serializer\SerializerInterface
    * @see core/core.link_relation_types.yml
    */
    public function __construct(
    public readonly string $id,
    public readonly TranslatableMarkup $label,
    public readonly ?string $serialization_class = NULL,
    public readonly ?string $deriver = NULL,
    public readonly array $uri_paths = [],
    ) {}
    }
    ...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
    use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\CacheBackendInterface;
    use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
    use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Plugin\DefaultPluginManager;
    use Drupal\rest\Attribute\RestResource;
    use Drupal\rest\Plugin\ResourceInterface;
    /** /**
    * Manages discovery and instantiation of resource plugins. * Manages discovery and instantiation of resource plugins.
    ...@@ -28,7 +30,14 @@ class ResourcePluginManager extends DefaultPluginManager { ...@@ -28,7 +30,14 @@ class ResourcePluginManager extends DefaultPluginManager {
    * The module handler to invoke the alter hook with. * The module handler to invoke the alter hook with.
    */ */
    public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    parent::__construct('Plugin/rest/resource', $namespaces, $module_handler, 'Drupal\rest\Plugin\ResourceInterface', 'Drupal\rest\Annotation\RestResource'); parent::__construct(
    'Plugin/rest/resource',
    $namespaces,
    $module_handler,
    ResourceInterface::class,
    RestResource::class,
    'Drupal\rest\Annotation\RestResource',
    );
    $this->setCacheBackend($cache_backend, 'rest_plugins'); $this->setCacheBackend($cache_backend, 'rest_plugins');
    $this->alterInfo('rest_resource'); $this->alterInfo('rest_resource');
    ......
    ...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
    use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityStorageException;
    use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
    use Drupal\Core\Routing\AccessAwareRouterInterface; use Drupal\Core\Routing\AccessAwareRouterInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\rest\Attribute\RestResource;
    use Drupal\rest\Plugin\Deriver\EntityDeriver;
    use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\Plugin\ResourceBase;
    use Drupal\rest\ResourceResponse; use Drupal\rest\ResourceResponse;
    use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
    ...@@ -29,18 +32,17 @@ ...@@ -29,18 +32,17 @@
    * Represents entities as resources. * Represents entities as resources.
    * *
    * @see \Drupal\rest\Plugin\Deriver\EntityDeriver * @see \Drupal\rest\Plugin\Deriver\EntityDeriver
    *
    * @RestResource(
    * id = "entity",
    * label = @Translation("Entity"),
    * serialization_class = "Drupal\Core\Entity\Entity",
    * deriver = "Drupal\rest\Plugin\Deriver\EntityDeriver",
    * uri_paths = {
    * "canonical" = "/entity/{entity_type}/{entity}",
    * "create" = "/entity/{entity_type}"
    * }
    * )
    */ */
    #[RestResource(
    id: "entity",
    label: new TranslatableMarkup("Entity"),
    serialization_class: "Drupal\Core\Entity\Entity",
    deriver: EntityDeriver::class,
    uri_paths: [
    "canonical" => "/entity/{entity_type}/{entity}",
    "create" => "/entity/{entity_type}",
    ],
    )]
    class EntityResource extends ResourceBase implements DependentPluginInterface { class EntityResource extends ResourceBase implements DependentPluginInterface {
    use EntityResourceValidationTrait; use EntityResourceValidationTrait;
    ......
    ...@@ -2,19 +2,20 @@ ...@@ -2,19 +2,20 @@
    namespace Drupal\rest_test\Plugin\rest\resource; namespace Drupal\rest_test\Plugin\rest\resource;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\rest\Attribute\RestResource;
    use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\Plugin\ResourceBase;
    use Drupal\rest\ResourceResponse; use Drupal\rest\ResourceResponse;
    /** /**
    * Class used to test that serialization_class is optional. * Class used to test that serialization_class is optional.
    *
    * @RestResource(
    * id = "serialization_test",
    * label = @Translation("Optional serialization_class"),
    * serialization_class = "",
    * uri_paths = {}
    * )
    */ */
    #[RestResource(
    id: "serialization_test",
    label: new TranslatableMarkup("Optional serialization_class"),
    serialization_class: "",
    uri_paths: []
    )]
    class NoSerializationClassTestResource extends ResourceBase { class NoSerializationClassTestResource extends ResourceBase {
    /** /**
    ......
    ...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
    use Drupal\Core\Config\ImmutableConfig; use Drupal\Core\Config\ImmutableConfig;
    use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\rest\Attribute\RestResource;
    use Drupal\rest\ModifiedResourceResponse; use Drupal\rest\ModifiedResourceResponse;
    use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\Plugin\ResourceBase;
    use Drupal\rest\Plugin\rest\resource\EntityResourceAccessTrait; use Drupal\rest\Plugin\rest\resource\EntityResourceAccessTrait;
    use Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait; use Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait;
    use Drupal\user\Entity\User;
    use Drupal\user\UserInterface; use Drupal\user\UserInterface;
    use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
    ...@@ -17,16 +20,15 @@ ...@@ -17,16 +20,15 @@
    /** /**
    * Represents user registration as a resource. * Represents user registration as a resource.
    *
    * @RestResource(
    * id = "user_registration",
    * label = @Translation("User registration"),
    * serialization_class = "Drupal\user\Entity\User",
    * uri_paths = {
    * "create" = "/user/register",
    * },
    * )
    */ */
    #[RestResource(
    id: "user_registration",
    label: new TranslatableMarkup("User registration"),
    serialization_class: User::class,
    uri_paths: [
    "create" => "/user/register",
    ],
    )]
    class UserRegistrationResource extends ResourceBase { class UserRegistrationResource extends ResourceBase {
    use EntityResourceValidationTrait; use EntityResourceValidationTrait;
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment