TextfieldWidget.php in Drupal 10
File
core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php
View source
<?php
namespace Drupal\text\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\Validator\ConstraintViolationInterface;
class TextfieldWidget extends StringTextfieldWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$main_widget = parent::formElement($items, $delta, $element, $form, $form_state);
$element = $main_widget['value'];
$element['#type'] = 'text_format';
$element['#format'] = $items[$delta]->format ?? NULL;
$element['#base_type'] = $main_widget['value']['#type'];
return $element;
}
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
if ($violation->arrayPropertyPath == [
'format',
] && isset($element['format']['#access']) && !$element['format']['#access']) {
return FALSE;
}
return $element;
}
}