YamlEditorWidget.php in YAML editor 8
File
src/Plugin/Field/FieldWidget/YamlEditorWidget.php
View source
<?php
namespace Drupal\yaml_editor\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget;
use Drupal\Core\Form\FormStateInterface;
class YamlEditorWidget extends StringTextareaWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['value'] = $element + [
'#type' => 'textarea',
'#default_value' => $items[$delta]->value,
'#rows' => $this
->getSetting('rows'),
'#placeholder' => $this
->getSetting('placeholder'),
'#attributes' => [
'data-yaml-editor' => 'true',
'class' => [
'js-text-full',
'text-full',
],
],
];
return $element;
}
}