Skip to content

Commit

Permalink
Merge pull request #162 from Chi-teck/php-attribute-entity-reference-…
Browse files Browse the repository at this point in the history
…selection

Use PHP attribute for EntityReferenceSelection plugin.
  • Loading branch information
Chi-teck committed May 21, 2024
2 parents f8be681 + cefb837 commit 7541424
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ declare(strict_types=1);
namespace Drupal\{{ machine_name }}\Plugin\EntityReferenceSelection;

{% apply sort_namespaces %}
use Drupal\Core\Entity\Attribute\EntityReferenceSelection;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
{% if configurable %}
use Drupal\Core\Form\FormStateInterface;
{% endif %}
Expand All @@ -14,14 +16,14 @@ use {{ base_class_full }}{% if base_class == class %} as Base{{ base_class }}{%

/**
* @todo Add plugin description here.
*
* @EntityReferenceSelection(
* id = "{{ plugin_id }}",
* label = @Translation("{{ plugin_label }}"),
* group = "{{ plugin_id }}",
* entity_types = {"{{ entity_type }}"},
* )
*/
#[EntityReferenceSelection(
id: '{{ plugin_id }}',
label: new TranslatableMarkup('{{ plugin_label }}'),
group: '{{ plugin_id }}',
weight: 1,
entity_types: ['{{ entity_type }}'],
)]
final class {{ class }} extends {{ base_class == class ? 'Base' ~ base_class : base_class }} {

{% if configurable %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

namespace Drupal\example\Plugin\EntityReferenceSelection;

use Drupal\Core\Entity\Attribute\EntityReferenceSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* @todo Add plugin description here.
*
* @EntityReferenceSelection(
* id = "contact_message_selection",
* label = @Translation("Contact message selection"),
* group = "contact_message_selection",
* entity_types = {"contact_message"},
* )
*/
#[EntityReferenceSelection(
id: 'contact_message_selection',
label: new TranslatableMarkup('Contact message selection'),
group: 'contact_message_selection',
weight: 1,
entity_types: ['contact_message'],
)]
final class ContactMessageSelection extends DefaultSelection {

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

namespace Drupal\example\Plugin\EntityReferenceSelection;

use Drupal\Core\Entity\Attribute\EntityReferenceSelection;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\Plugin\EntityReferenceSelection\NodeSelection;

/**
* @todo Add plugin description here.
*
* @EntityReferenceSelection(
* id = "example_node_selection",
* label = @Translation("Advanced node selection"),
* group = "example_node_selection",
* entity_types = {"node"},
* )
*/
#[EntityReferenceSelection(
id: 'example_node_selection',
label: new TranslatableMarkup('Advanced node selection'),
group: 'example_node_selection',
weight: 1,
entity_types: ['node'],
)]
final class ExampleNodeSelection extends NodeSelection {

/**
Expand Down

0 comments on commit 7541424

Please sign in to comment.