TwigFieldForm.php in Display Suite 8.4
File
src/Form/TwigFieldForm.php
View source
<?php
namespace Drupal\ds\Form;
use Drupal\Core\Form\FormStateInterface;
class TwigFieldForm extends FieldFormBase {
const TYPE = 'twig';
public function getFormId() {
return 'ds_field_twig_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' => 'textarea',
'#title' => $this
->t('Template'),
'#rows' => 5,
'#default_value' => isset($field['properties']['content']) ? $field['properties']['content'] : '',
'#required' => TRUE,
];
return $form;
}
public function getProperties(FormStateInterface $form_state) {
return [
'content' => $form_state
->getValue('content'),
];
}
public function getType() {
return TwigFieldForm::TYPE;
}
public function getTypeLabel() {
return 'Twig field';
}
}