From c98f1c4c47515513ef370a77ae0faf596ef3fe92 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 10 Oct 2024 19:20:25 -0700 Subject: [PATCH] convert plugins from aannotations to attributes --- .../src/Plugin/Block/PageHeadingBlock.php | 11 +++++----- .../src/Plugin/Block/SkipNavAnchorBlock.php | 11 +++++----- .../Condition/ResponseCodeCondition.php | 19 +++++++----------- .../process/ExploreCoursesInstructors.php | 6 ++---- .../process/ExploreCoursesQuarters.php | 6 ++---- .../migrate/process/ExploreCoursesTags.php | 6 ++---- .../migrate/process/ExploreCoursesUnits.php | 6 ++---- .../FieldWidget/ExploreCoursesUrlWidget.php | 15 +++++++------- .../src/Plugin/Filter/SuCleanHtml.php | 20 +++++++++---------- .../DecoupledReferencedInvalidated.php | 13 ++++++------ ...tanfordEventsImporterAPIURLFieldWidget.php | 16 +++++++-------- .../src/Plugin/migrate/process/DateMath.php | 6 ++---- .../Field/FieldType/EntityAccessFieldType.php | 17 ++++++++-------- .../FieldWidget/EntityAccessFieldWidget.php | 18 ++++++++--------- .../src/Plugin/Block/SignupBlock.php | 13 ++++++------ 15 files changed, 83 insertions(+), 100 deletions(-) diff --git a/modules/jumpstart_ui/src/Plugin/Block/PageHeadingBlock.php b/modules/jumpstart_ui/src/Plugin/Block/PageHeadingBlock.php index fb428b29..abc3ff76 100644 --- a/modules/jumpstart_ui/src/Plugin/Block/PageHeadingBlock.php +++ b/modules/jumpstart_ui/src/Plugin/Block/PageHeadingBlock.php @@ -2,17 +2,18 @@ namespace Drupal\jumpstart_ui\Plugin\Block; +use Drupal\Core\Block\Attribute\Block; use Drupal\Core\Block\BlockBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Provides a block that outputs an h1 tag. - * - * @Block( - * id = "jumpstart_ui_page_heading", - * admin_label = @Translation("Heading Block"), - * ) */ +#[Block( + id: "jumpstart_ui_page_heading", + admin_label: new TranslatableMarkup("Heading Block") +)] class PageHeadingBlock extends BlockBase { /** diff --git a/modules/jumpstart_ui/src/Plugin/Block/SkipNavAnchorBlock.php b/modules/jumpstart_ui/src/Plugin/Block/SkipNavAnchorBlock.php index 4d582e46..dff1cd3f 100644 --- a/modules/jumpstart_ui/src/Plugin/Block/SkipNavAnchorBlock.php +++ b/modules/jumpstart_ui/src/Plugin/Block/SkipNavAnchorBlock.php @@ -3,16 +3,17 @@ namespace Drupal\jumpstart_ui\Plugin\Block; use Drupal\Component\Utility\Html; +use Drupal\Core\Block\Attribute\Block; use Drupal\Core\Block\BlockBase; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Provides a block with a hidden anchor. - * - * @Block( - * id = "jumpstart_ui_skipnav_main_anchor", - * admin_label = @Translation("Main content anchor target"), - * ) */ +#[Block( + id: "jumpstart_ui_skipnav_main_anchor", + admin_label: new TranslatableMarkup("Main content anchor target") +)] class SkipNavAnchorBlock extends BlockBase { /** diff --git a/modules/response_code_condition/src/Plugin/Condition/ResponseCodeCondition.php b/modules/response_code_condition/src/Plugin/Condition/ResponseCodeCondition.php index 3ca320fa..26a9910a 100644 --- a/modules/response_code_condition/src/Plugin/Condition/ResponseCodeCondition.php +++ b/modules/response_code_condition/src/Plugin/Condition/ResponseCodeCondition.php @@ -2,28 +2,24 @@ namespace Drupal\response_code_condition\Plugin\Condition; +use Drupal\Core\Condition\Attribute\Condition; use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; /** * Provides a 'Response code' condition. - * - * @Condition( - * id = "response_code", - * label = @Translation("Response code"), - * ) */ +#[Condition( + id: "response_code", + label: new TranslatableMarkup("Response code") +)] class ResponseCodeCondition extends ConditionPluginBase implements ContainerFactoryPluginInterface { - /** - * @var Symfony\Component\HttpFoundation\RequestStack - */ - private $requestStack; - /** * Creates a new Response code instance. * @@ -39,9 +35,8 @@ class ResponseCodeCondition extends ConditionPluginBase implements ContainerFact * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack * The request stack. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $requestStack) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, protected RequestStack $requestStack) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->requestStack = $requestStack; } /** diff --git a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesInstructors.php b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesInstructors.php index fce20a5c..13933051 100644 --- a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesInstructors.php +++ b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesInstructors.php @@ -2,17 +2,15 @@ namespace Drupal\stanford_courses_importer\Plugin\migrate\process; +use Drupal\migrate\Attribute\MigrateProcess; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** * Provides a 'ExploreCoursesInstructors' migrate process plugin. - * - * @MigrateProcessPlugin( - * id = "explore_courses_instructors" - * ) */ +#[MigrateProcess(id: "explore_courses_instructors")] class ExploreCoursesInstructors extends ProcessPluginBase { /** diff --git a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesQuarters.php b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesQuarters.php index 182a1011..78700be2 100644 --- a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesQuarters.php +++ b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesQuarters.php @@ -2,17 +2,15 @@ namespace Drupal\stanford_courses_importer\Plugin\migrate\process; +use Drupal\migrate\Attribute\MigrateProcess; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** * Provides a 'ExploreCoursesQuarters' migrate process plugin. - * - * @MigrateProcessPlugin( - * id = "explore_courses_quarters" - * ) */ +#[MigrateProcess(id: "explore_courses_quarters")] class ExploreCoursesQuarters extends ProcessPluginBase { /** diff --git a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesTags.php b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesTags.php index 86870b4e..4f8c080a 100644 --- a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesTags.php +++ b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesTags.php @@ -2,17 +2,15 @@ namespace Drupal\stanford_courses_importer\Plugin\migrate\process; +use Drupal\migrate\Attribute\MigrateProcess; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** * Provides a 'ExploreCoursesTags' migrate process plugin. - * - * @MigrateProcessPlugin( - * id = "explore_courses_tags" - * ) */ +#[MigrateProcess(id: "explore_courses_tags")] class ExploreCoursesTags extends ProcessPluginBase { /** diff --git a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesUnits.php b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesUnits.php index f6c8ce9d..d99258c4 100644 --- a/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesUnits.php +++ b/modules/stanford_courses/modules/stanford_courses_importer/src/Plugin/migrate/process/ExploreCoursesUnits.php @@ -2,17 +2,15 @@ namespace Drupal\stanford_courses_importer\Plugin\migrate\process; +use Drupal\migrate\Attribute\MigrateProcess; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** * Provides a 'ExploreCoursesUnits' migrate process plugin. - * - * @MigrateProcessPlugin( - * id = "explore_courses_units" - * ) */ +#[MigrateProcess(id: "explore_courses_units")] class ExploreCoursesUnits extends ProcessPluginBase { /** diff --git a/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php b/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php index 8b7850d5..63ac5d8e 100644 --- a/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php +++ b/modules/stanford_courses/src/Plugin/Field/FieldWidget/ExploreCoursesUrlWidget.php @@ -4,9 +4,11 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\Field\Attribute\FieldWidget; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\link\Plugin\Field\FieldWidget\LinkWidget; use GuzzleHttp\ClientInterface; @@ -14,15 +16,12 @@ /** * Plugin implementation of the 'explore_courses_url' widget. - * - * @FieldWidget( - * id = "explore_courses_url", - * label = @Translation("ExploreCourses"), - * field_types = { - * "link" - * } - * ) */ +#[FieldWidget( + id: "explore_courses_url", + label: new TranslatableMarkup("ExploreCourses"), + field_types: ["link"] +)] class ExploreCoursesUrlWidget extends LinkWidget { /** diff --git a/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php b/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php index c3a60bb3..0a5ffde5 100644 --- a/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php +++ b/modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php @@ -4,23 +4,23 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\filter\Attribute\Filter; use Drupal\filter\FilterProcessResult; use Drupal\filter\Plugin\FilterBase; +use Drupal\filter\Plugin\FilterInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a 'Clean Html' filter. - * - * @Filter( - * id = "su_clean_html", - * title = @Translation("Clean Html"), - * description = @Translation("Remove line breaks, html comments, and white - * space between tags. Requires - * stanford_profile_helper.decoupled state to be true."), type = - * Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE, weight - * = 99 - * ) */ +#[Filter( + id: "su_clean_html", + title: new TranslatableMarkup("Clean Html"), + description: new TranslatableMarkup("Remove line breaks, html comments, and white space between tags."), + type: FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE, + weight: 99 +)] class SuCleanHtml extends FilterBase implements ContainerFactoryPluginInterface { /** diff --git a/modules/stanford_decoupled/src/Plugin/QueueWorker/DecoupledReferencedInvalidated.php b/modules/stanford_decoupled/src/Plugin/QueueWorker/DecoupledReferencedInvalidated.php index 5831926e..5ffafdf4 100644 --- a/modules/stanford_decoupled/src/Plugin/QueueWorker/DecoupledReferencedInvalidated.php +++ b/modules/stanford_decoupled/src/Plugin/QueueWorker/DecoupledReferencedInvalidated.php @@ -6,20 +6,21 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Queue\Attribute\QueueWorker; use Drupal\Core\Queue\QueueWorkerBase; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines 'decoupled_referenced_invalidated' queue worker. * * @codeCoverageIgnore since it calls an external api, we can't test. - * - * @QueueWorker( - * id = "decoupled_referenced_invalidator", - * title = @Translation("Decoupled Referenced Invalidator"), - * cron = {"time" = 60}, - * ) */ +#[QueueWorker( + id: "decoupled_referenced_invalidator", + title: new TranslatableMarkup("Decoupled Referenced Invalidator"), + cron: ["time" => 60], +)] final class DecoupledReferencedInvalidated extends QueueWorkerBase implements ContainerFactoryPluginInterface { /** diff --git a/modules/stanford_events/modules/stanford_events_importer/src/Plugin/Field/FieldWidget/StanfordEventsImporterAPIURLFieldWidget.php b/modules/stanford_events/modules/stanford_events_importer/src/Plugin/Field/FieldWidget/StanfordEventsImporterAPIURLFieldWidget.php index 72a5b338..518b3e19 100644 --- a/modules/stanford_events/modules/stanford_events_importer/src/Plugin/Field/FieldWidget/StanfordEventsImporterAPIURLFieldWidget.php +++ b/modules/stanford_events/modules/stanford_events_importer/src/Plugin/Field/FieldWidget/StanfordEventsImporterAPIURLFieldWidget.php @@ -2,7 +2,9 @@ namespace Drupal\stanford_events_importer\Plugin\Field\FieldWidget; +use Drupal\Core\Field\Attribute\FieldWidget; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\link\LinkItemInterface; use Drupal\Component\Utility\UrlHelper; use Drupal\link\Plugin\Field\FieldWidget\LinkWidget; @@ -14,16 +16,12 @@ /** * Plugin implementation of the 'stanford_events_importer_apiurl_field_widget'. - * - * @FieldWidget( - * id = "stanford_events_importer_apiurl_field_widget", - * module = "stanford_events_importer", - * label = @Translation("Stanford Events API URL Builder Widget"), - * field_types = { - * "link" - * } - * ) */ +#[FieldWidget( + id: "stanford_events_importer_apiurl_field_widget", + label: new TranslatableMarkup("Stanford Events API URL Builder Widget"), + field_types: ["link"] +)] class StanfordEventsImporterAPIURLFieldWidget extends LinkWidget { /** diff --git a/modules/stanford_events/modules/stanford_events_importer/src/Plugin/migrate/process/DateMath.php b/modules/stanford_events/modules/stanford_events_importer/src/Plugin/migrate/process/DateMath.php index 37c2ef53..8029d769 100644 --- a/modules/stanford_events/modules/stanford_events_importer/src/Plugin/migrate/process/DateMath.php +++ b/modules/stanford_events/modules/stanford_events_importer/src/Plugin/migrate/process/DateMath.php @@ -2,6 +2,7 @@ namespace Drupal\stanford_events_importer\Plugin\migrate\process; +use Drupal\migrate\Attribute\MigrateProcess; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; @@ -26,11 +27,8 @@ * @endcode * * This will perform the mathematical operation on the date strings. - * - * @MigrateProcessPlugin( - * id = "stanford_events_datemath" - * ) */ +#[MigrateProcess(id: "stanford_events_datemath")] class DateMath extends ProcessPluginBase { /** diff --git a/modules/stanford_intranet/src/Plugin/Field/FieldType/EntityAccessFieldType.php b/modules/stanford_intranet/src/Plugin/Field/FieldType/EntityAccessFieldType.php index 5daab016..ba649537 100644 --- a/modules/stanford_intranet/src/Plugin/Field/FieldType/EntityAccessFieldType.php +++ b/modules/stanford_intranet/src/Plugin/Field/FieldType/EntityAccessFieldType.php @@ -2,6 +2,7 @@ namespace Drupal\stanford_intranet\Plugin\Field\FieldType; +use Drupal\Core\Field\Attribute\FieldType; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -9,16 +10,14 @@ /** * Plugin implementation of the 'entity_access' field type. - * - * @FieldType( - * id = "entity_access", - * label = @Translation("Entity access field type"), - * description = @Translation("My Field Type"), - * no_ui = TRUE, - * default_widget = "language_select", - * cardinality = \Drupal\Core\Field\FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED - * ) */ +#[FieldType( + id: "entity_access", + label: new TranslatableMarkup("Entity access field type"), + default_widget: "language_select", + cardinality: FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + no_ui: TRUE +)] class EntityAccessFieldType extends FieldItemBase { const FIELD_NAME = 'stanford_intranet__access'; diff --git a/modules/stanford_intranet/src/Plugin/Field/FieldWidget/EntityAccessFieldWidget.php b/modules/stanford_intranet/src/Plugin/Field/FieldWidget/EntityAccessFieldWidget.php index 62cc7e08..fd4e2781 100644 --- a/modules/stanford_intranet/src/Plugin/Field/FieldWidget/EntityAccessFieldWidget.php +++ b/modules/stanford_intranet/src/Plugin/Field/FieldWidget/EntityAccessFieldWidget.php @@ -2,26 +2,24 @@ namespace Drupal\stanford_intranet\Plugin\Field\FieldWidget; +use Drupal\Core\Field\Attribute\FieldWidget; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\State\StateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'entity_access' widget. - * - * @FieldWidget( - * id = "entity_access", - * module = "stanford_intranet", - * label = @Translation("Entity Access"), - * field_types = { - * "entity_access" - * }, - * multiple_values = TRUE - * ) */ +#[FieldWidget( + id: "entity_access", + label: new TranslatableMarkup("Entity Access"), + field_types: ["entity_access"], + multiple_values: TRUE +)] class EntityAccessFieldWidget extends WidgetBase { /** diff --git a/modules/stanford_news/src/Plugin/Block/SignupBlock.php b/modules/stanford_news/src/Plugin/Block/SignupBlock.php index f83ef3d5..b8d89680 100644 --- a/modules/stanford_news/src/Plugin/Block/SignupBlock.php +++ b/modules/stanford_news/src/Plugin/Block/SignupBlock.php @@ -3,20 +3,21 @@ namespace Drupal\stanford_news\Plugin\Block; use Drupal\Core\Access\AccessResultForbidden; +use Drupal\Core\Block\Attribute\Block; use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Provides a 'Newsletter Signup' Block. - * - * @Block( - * id = "signup_block", - * admin_label = @Translation("Newsletter Signup"), - * category = @Translation("Stanford News"), - * ) */ +#[Block( + id: "signup_block", + admin_label: new TranslatableMarkup("Newsletter Signup"), + category: new TranslatableMarkup("Stanford News") +)] class SignupBlock extends BlockBase implements BlockPluginInterface { /**