public function TemplateForm::form in Wysiwyg API template plugin 8.2
Same name and namespace in other branches
- 3.0.x src/Form/TemplateForm.php \Drupal\wysiwyg_template\Form\TemplateForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ TemplateForm.php, line 19
Class
- TemplateForm
- Class TemplateForm.
Namespace
Drupal\wysiwyg_template\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\wysiwyg_template_core\TemplateInterface $wysiwyg_template */
$wysiwyg_template = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#maxlength' => 255,
'#default_value' => $wysiwyg_template
->label(),
'#description' => $this
->t('Select a name for this template.'),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $wysiwyg_template
->id(),
'#machine_name' => array(
'exists' => '\\Drupal\\wysiwyg_template\\Entity\\Template::load',
),
'#disabled' => !$wysiwyg_template
->isNew(),
];
$form['description'] = [
'#type' => 'textfield',
'#default_value' => $wysiwyg_template
->getDescription(),
'#title' => $this
->t('Description'),
'#description' => $this
->t('A description to be shown with the template.'),
];
$form['body'] = [
'#type' => 'text_format',
'#format' => $wysiwyg_template
->getFormat(),
'#default_value' => $wysiwyg_template
->getBody(),
'#title' => $this
->t('HTML template'),
'#rows' => 10,
'#required' => TRUE,
];
$node_types = array_map(static function ($item) {
return $item
->label();
}, NodeType::loadMultiple());
$form['node_types'] = [
'#type' => 'checkboxes',
'#default_value' => $wysiwyg_template
->getNodeTypes(),
'#title' => $this
->t('Available for content types'),
'#description' => $this
->t('If you select no content type, this template will be available for all content types.'),
'#access' => (bool) count($node_types),
'#options' => $node_types,
];
return $form;
}