3 namespace Drupal\Core\Display;
5 use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Plugin\PluginBase;
8 use Drupal\Core\Plugin\PluginDependencyTrait;
9 use Drupal\Core\Session\AccountInterface;
12 * Provides a base class for DisplayVariant plugins.
14 * @see \Drupal\Core\Display\Annotation\DisplayVariant
15 * @see \Drupal\Core\Display\VariantInterface
16 * @see \Drupal\Core\Display\VariantManager
19 abstract class VariantBase extends PluginBase implements VariantInterface {
21 use PluginDependencyTrait;
22 use RefinableCacheableDependencyTrait;
27 public function __construct(array $configuration, $plugin_id, $plugin_definition) {
28 parent::__construct($configuration, $plugin_id, $plugin_definition);
30 $this->setConfiguration($configuration);
36 public function label() {
37 return $this->configuration['label'];
43 public function adminLabel() {
44 return $this->pluginDefinition['admin_label'];
50 public function id() {
51 return $this->configuration['uuid'];
57 public function getWeight() {
58 return (int) $this->configuration['weight'];
64 public function setWeight($weight) {
65 $this->configuration['weight'] = (int) $weight;
71 public function getConfiguration() {
73 'id' => $this->getPluginId(),
74 ] + $this->configuration;
80 public function setConfiguration(array $configuration) {
81 $this->configuration = $configuration + $this->defaultConfiguration();
88 public function defaultConfiguration() {
99 public function calculateDependencies() {
100 return $this->dependencies;
106 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
108 '#type' => 'textfield',
109 '#title' => $this->t('Label'),
110 '#description' => $this->t('The label for this display variant.'),
111 '#default_value' => $this->label(),
112 '#maxlength' => '255',
120 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
126 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
127 $this->configuration['label'] = $form_state->getValue('label');
133 public function access(AccountInterface $account = NULL) {