function EntityReferenceSelection::__construct

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Entity/Attribute/EntityReferenceSelection.php \Drupal\Core\Entity\Attribute\EntityReferenceSelection::__construct()

Constructs an EntityReferenceSelection attribute.

Parameters

string $id: The plugin ID. There are some implementation bugs that make the plugin available only if the ID follows a specific pattern. It must be either identical to group or prefixed with the group. E.g. if the group is "foo" the ID must be either "foo" or "foo:bar".

\Drupal\Core\StringTranslation\TranslatableMarkup $label: The human-readable name of the selection plugin.

string $group: The selection plugin group. This property is used to allow selection plugins to target a specific entity type while also inheriting the code of an existing selection plugin. For example, if we want to override the NodeSelection from the 'default' selection type, we can define the attribute as follows:


  #[EntityReferenceSelection(
    id: "default:node_advanced",
    entity_types: ["node"],
    group: "default",
    weight: 5
  )]
  

int $weight: The weight of the plugin in its group. This property is used to select the "best" plugin within a group.

string[] $entity_types: (optional) An array of entity types that can be referenced by this plugin. Defaults to all entity types.

class-string|null $deriver: (optional) The deriver class.

Overrides Plugin::__construct

File

core/lib/Drupal/Core/Entity/Attribute/EntityReferenceSelection.php, line 56

Class

EntityReferenceSelection
Defines an EntityReferenceSelection attribute for plugin discovery.

Namespace

Drupal\Core\Entity\Attribute

Code

public function __construct(string $id, TranslatableMarkup $label, string $group, int $weight, array $entity_types = [], ?string $deriver = NULL) {
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.