diff --git a/src/Attribute/RdfUriGenerator.php b/src/Attribute/RdfUriGenerator.php new file mode 100644 index 0000000000000000000000000000000000000000..f1271885aaf45e05fb818ec889b2ccef851e6c85 --- /dev/null +++ b/src/Attribute/RdfUriGenerator.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\rdf_sync\Attribute; + +use Drupal\Component\Plugin\Attribute\Plugin; +use Drupal\Core\StringTranslation\TranslatableMarkup; + +/** + * Defines an RdfUriGenerator. + */ +#[\Attribute(\Attribute::TARGET_CLASS)] +class RdfUriGenerator extends Plugin { + + /** + * Constructs an RDF URI generator attribute. + * + * @param string $id + * The plugin ID. + * @param \Drupal\Core\StringTranslation\TranslatableMarkup $label + * The human-readable name of the widget type. + */ + public function __construct( + public readonly string $id, + public readonly TranslatableMarkup $label, + ) {} + +} diff --git a/src/Plugin/rdf_sync/RdfUriGenerator/DefaultRdfUriGenerator.php b/src/Plugin/rdf_sync/RdfUriGenerator/DefaultRdfUriGenerator.php index 4f9dfd9bbb72d57b5c1c2c5ac19ddf8006437267..977abaf8ac0d770d33a6ce0ef357e9af4e8ae45b 100644 --- a/src/Plugin/rdf_sync/RdfUriGenerator/DefaultRdfUriGenerator.php +++ b/src/Plugin/rdf_sync/RdfUriGenerator/DefaultRdfUriGenerator.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace Drupal\rdf_sync\Plugin\rdf_sync\RdfUriGenerator; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\rdf_sync\Attribute\RdfUriGenerator; use Drupal\rdf_sync\RdfUriGeneratorPluginBase; /** * Provides a fallback entity ID generator plugin. - * - * @RdfUriGenerator( - * id = "default", - * name = @Translation("Default URI generator"), - * ) */ +#[RdfUriGenerator( + id: "default", + label: new TranslatableMarkup("Default URI generator"), +)] class DefaultRdfUriGenerator extends RdfUriGeneratorPluginBase { /** diff --git a/src/RdfUriGeneratorPluginManager.php b/src/RdfUriGeneratorPluginManager.php index 3ae9588fb2021564a96c02a56e61115638252ee0..a4f8b5173810eaae933d4480097c938ae3eb90e2 100644 --- a/src/RdfUriGeneratorPluginManager.php +++ b/src/RdfUriGeneratorPluginManager.php @@ -8,7 +8,8 @@ use Drupal\Component\Plugin\FallbackPluginManagerInterface; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\rdf_sync\Annotation\RdfUriGenerator; +use Drupal\rdf_sync\Annotation\RdfUriGenerator as AnnotationRdfUriGenerator; +use Drupal\rdf_sync\Attribute\RdfUriGenerator as AttributeRdfUriGenerator; /** * Plugin manager for RDF URI generator plugins. @@ -27,7 +28,8 @@ class RdfUriGeneratorPluginManager extends DefaultPluginManager implements Fallb * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/rdf_sync/RdfUriGenerator', $namespaces, $module_handler, RdfUriGeneratorPluginInterface::class, RdfUriGenerator::class); + parent::__construct('Plugin/rdf_sync/RdfUriGenerator', $namespaces, $module_handler, RdfUriGeneratorPluginInterface::class, + AttributeRdfUriGenerator::class, AnnotationRdfUriGenerator::class); $this->alterInfo('rdf_uri_generator_info'); $this->setCacheBackend($cache_backend, 'rdf_uri_generator_plugins'); }