5 * Contains \Drupal\linkit\Plugin\Linkit\Attribute\Target.
8 namespace Drupal\linkit\Plugin\Linkit\Attribute;
10 use Drupal\Core\Form\FormStateInterface;
11 use Drupal\linkit\ConfigurableAttributeBase;
18 * label = @Translation("Target"),
19 * html_name = "target"
22 class Target extends ConfigurableAttributeBase {
24 const SELECT_LIST = 'select_list';
25 const SIMPLE_CHECKBOX = 'simple_checkbox';
30 public function buildFormElement($default_value) {
31 switch ($this->configuration['widget_type']) {
32 case self::SELECT_LIST:
35 '#title' => t('Target'),
38 '_blank' => t('New window (_blank)'),
39 '_top' => t('Top window (_top)'),
40 '_self' => t('Same window (_self)'),
41 '_parent' => t('Parent window (_parent)')
43 '#default_value' => $default_value,
45 case self::SIMPLE_CHECKBOX:
47 '#type' => 'checkbox',
48 '#title' => t('Open in new window'),
49 '#default_value' => $default_value,
50 '#return_value' => '_blank',
60 public function defaultConfiguration() {
61 return parent::defaultConfiguration() + [
62 'widget_type' => self::SIMPLE_CHECKBOX,
69 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
70 $form['widget_type'] = [
72 '#title' => $this->t('Widget type'),
73 '#default_value' => $this->configuration['widget_type'],
75 self::SELECT_LIST => $this->t('Selectlist with predefined targets.'),
76 self::SIMPLE_CHECKBOX => $this->t('Simple checkbox to allow links to be opened in a new browser window or tab.'),
86 public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
92 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
93 $this->configuration['widget_type'] = $form_state->getValue('widget_type');