Skip to content
Snippets Groups Projects
Commit a4e5432d authored by Sviatoslav Smovdyr's avatar Sviatoslav Smovdyr Committed by Pierre Dureau
Browse files

Issue #3500669 by smovs, pdureau, grimreaper: From plugin Annotation to Attributes

parent 8d555ae1
No related branches found
No related tags found
1 merge request!325#3500669 - Switched from annotation to attributes in the FieldFormatter plugins.
Pipeline #401534 passed
......@@ -4,11 +4,13 @@ declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
/**
......@@ -16,12 +18,15 @@ use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
*
* Field types are altered in
* ui_patterns_field_formatters_field_formatter_info_alter().
*
* @FieldFormatter(
* id = "ui_patterns_component",
* label = @Translation("Component (UI Patterns)")
* )
*/
#[FieldFormatter(
id: 'ui_patterns_component',
label: new TranslatableMarkup('Component (UI Patterns)'),
description: new TranslatableMarkup('Render a field as a SDC.'),
field_types: [
'entity_reference',
],
)]
class ComponentFormatter extends ComponentFormatterBase {
/**
......
......@@ -4,9 +4,11 @@ declare(strict_types=1);
namespace Drupal\ui_patterns_field_formatters\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
/**
......@@ -14,12 +16,15 @@ use Drupal\ui_patterns\Plugin\Context\RequirementsContext;
*
* Field types are altered in
* ui_patterns_field_formatters_field_formatter_info_alter().
*
* @FieldFormatter(
* id = "ui_patterns_component_per_item",
* label = @Translation("Component per item (UI Patterns)"),
* )
*/
#[FieldFormatter(
id: 'ui_patterns_component_per_item',
label: new TranslatableMarkup('Component per item (UI Patterns)'),
description: new TranslatableMarkup('Render each field item as a SDC.'),
field_types: [
'entity_reference',
],
)]
class ComponentPerItemFormatter extends ComponentFormatterBase {
/**
......
......@@ -16,7 +16,7 @@ function ui_patterns_field_formatters_field_formatter_info_alter(array &$info) :
$field_types = array_keys($field_type_manager->getDefinitions());
// Allow any field to be formatted with ui patterns field formatters.
// Because it is impossible to assign a field formatter to every field types
// using the plugins annotations.
// using the plugins attributes.
$info['ui_patterns_component']['field_types'] = $field_types;
$info['ui_patterns_component_per_item']['field_types'] = $field_types;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment