Title.php in Linkit 8.4
File
src/Plugin/Linkit/Attribute/Title.php
View source
<?php
namespace Drupal\linkit\Plugin\Linkit\Attribute;
use Drupal\Core\Form\FormStateInterface;
use Drupal\linkit\ConfigurableAttributeBase;
class Title extends ConfigurableAttributeBase {
public function buildFormElement($default_value) {
$element = [
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $default_value,
'#maxlength' => 255,
'#size' => 40,
'#placeholder' => t('The "title" attribute value'),
];
if ($this->configuration['automatic_title']) {
$element['#attached']['library'][] = 'linkit/linkit.attribute.title';
$element['#placeholder'] = t('The "title" attribute value (auto populated)');
}
return $element;
}
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'automatic_title' => FALSE,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['automatic_title'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Automatically populate title'),
'#default_value' => $this->configuration['automatic_title'],
'#description' => $this
->t('Automatically populate the title attribute with the title from the match selection.'),
];
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['automatic_title'] = $form_state
->getValue('automatic_title');
}
}