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

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

(cherry picked from commit d17c8302)
parent fdd6ca5b
No related branches found
No related tags found
30 merge requests!122353526426-warning-for-missing,!12212Issue #3445525 by alexpott, japerry, catch, mglaman, longwave: Add BC layer...,!11958Issue #3490507 by alexpott, smustgrave: Fix bogus mocking in...,!11769Issue #3517987: Add option to contextual filters to encode slashes in query parameter.,!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #108838 passed with warnings
Pipeline: drupal

#108843

    ...@@ -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