You are here

MutliValueKeyInput.php in Key 8

File

tests/modules/key_test/src/Plugin/KeyInput/MutliValueKeyInput.php
View source
<?php

namespace Drupal\key_test\Plugin\KeyInput;

use Drupal\Core\Form\FormStateInterface;
use Drupal\key\Plugin\KeyInputBase;

/**
 * Defines a multi-value key input class.
 *
 * @KeyInput(
 *   id = "key_test_multi",
 *   label = @Translation("Test multivalue")
 * )
 */
class MutliValueKeyInput extends KeyInputBase {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'first' => '',
      'second' => '',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    return $form + [
      'first' => [
        '#type' => 'textfield',
        '#default_value' => $this->configuration['first'],
        '#title' => $this
          ->t('First'),
      ],
      'second' => [
        '#type' => 'textfield',
        '#default_value' => $this->configuration['second'],
        '#title' => $this
          ->t('Second'),
      ],
    ];
  }

}

Classes

Namesort descending Description
MutliValueKeyInput Defines a multi-value key input class.