Target.php in Linkit 8.4
File
src/Plugin/Linkit/Attribute/Target.php
View source
<?php
namespace Drupal\linkit\Plugin\Linkit\Attribute;
use Drupal\Core\Form\FormStateInterface;
use Drupal\linkit\ConfigurableAttributeBase;
class Target extends ConfigurableAttributeBase {
const SELECT_LIST = 'select_list';
const SIMPLE_CHECKBOX = 'simple_checkbox';
public function buildFormElement($default_value) {
switch ($this->configuration['widget_type']) {
case self::SELECT_LIST:
return [
'#type' => 'select',
'#title' => t('Target'),
'#options' => [
'' => '',
'_blank' => t('New window (_blank)'),
'_top' => t('Top window (_top)'),
'_self' => t('Same window (_self)'),
'_parent' => t('Parent window (_parent)'),
],
'#default_value' => $default_value,
];
case self::SIMPLE_CHECKBOX:
return [
'#type' => 'checkbox',
'#title' => t('Open in new window'),
'#default_value' => $default_value,
'#return_value' => '_blank',
];
}
return [];
}
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'widget_type' => self::SIMPLE_CHECKBOX,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['widget_type'] = [
'#type' => 'radios',
'#title' => $this
->t('Widget type'),
'#default_value' => $this->configuration['widget_type'],
'#options' => [
self::SELECT_LIST => $this
->t('Selectlist with predefined targets.'),
self::SIMPLE_CHECKBOX => $this
->t('Simple checkbox to allow links to be opened in a new browser window or tab.'),
],
];
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['widget_type'] = $form_state
->getValue('widget_type');
}
}