TokenFieldForm.php in Display Suite 8.3
File
src/Form/TokenFieldForm.php
View source
<?php
namespace Drupal\ds\Form;
use Drupal\Core\Form\FormStateInterface;
class TokenFieldForm extends FieldFormBase {
const TYPE = 'token';
public function getFormId() {
return 'ds_field_form';
}
public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') {
$form = parent::buildForm($form, $form_state, $field_key);
$field = $this->field;
$form['content'] = [
'#type' => 'text_format',
'#title' => $this
->t('Field content'),
'#default_value' => isset($field['properties']['content']['value']) ? $field['properties']['content']['value'] : '',
'#format' => isset($field['properties']['content']['format']) ? $field['properties']['content']['format'] : 'plain_text',
'#base_type' => 'textarea',
'#required' => TRUE,
];
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$form['tokens'] = [
'#title' => $this
->t('Tokens'),
'#type' => 'container',
'#states' => [
'invisible' => [
'input[name="use_token"]' => [
'checked' => FALSE,
],
],
],
];
$form['tokens']['help'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#global_types' => FALSE,
'#dialog' => TRUE,
];
}
return $form;
}
public function getProperties(FormStateInterface $form_state) {
return [
'content' => $form_state
->getValue('content'),
];
}
public function getType() {
return TokenFieldForm::TYPE;
}
public function getTypeLabel() {
return 'Token field';
}
}