Skip to content

Commit

Permalink
convert plugins from aannotations to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Oct 11, 2024
1 parent e3b7d28 commit c98f1c4
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 100 deletions.
11 changes: 6 additions & 5 deletions modules/jumpstart_ui/src/Plugin/Block/PageHeadingBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
11 changes: 6 additions & 5 deletions modules/jumpstart_ui/src/Plugin/Block/SkipNavAnchorBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@

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;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* 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 {

/**
Expand Down
20 changes: 10 additions & 10 deletions modules/stanford_decoupled/src/Plugin/Filter/SuCleanHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <code>stanford_profile_helper.decoupled</code> 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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

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;
use Drupal\Core\TypedData\DataDefinition;

/**
* 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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
Loading

0 comments on commit c98f1c4

Please sign in to comment.