summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/text
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/text')
-rw-r--r--core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php21
-rw-r--r--core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php4
2 files changed, 14 insertions, 11 deletions
diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php
index 16b7549681c..289fbbd332c 100644
--- a/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php
+++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php
@@ -6,7 +6,10 @@ use Drupal\Core\Field\Attribute\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Render\Element\ElementInterface;
+use Drupal\Core\Render\Element\Widget;
use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\filter\Element\TextFormat;
use Symfony\Component\Validator\ConstraintViolationInterface;
/**
@@ -22,20 +25,20 @@ class TextfieldWidget extends StringTextfieldWidget {
/**
* {@inheritdoc}
*/
- public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
- $main_widget = parent::formElement($items, $delta, $element, $form, $form_state);
+ public function singleElementObject(FieldItemListInterface $items, $delta, Widget $widget, ElementInterface $form, FormStateInterface $form_state): ElementInterface {
+ $widget = parent::singleElementObject($items, $delta, $widget, $form, $form_state);
$allowed_formats = $this->getFieldSetting('allowed_formats');
- $element = $main_widget['value'];
- $element['#type'] = 'text_format';
- $element['#format'] = $items[$delta]->format ?? NULL;
- $element['#base_type'] = $main_widget['value']['#type'];
-
+ $widget = $widget->getChild('value');
+ $type = $widget->type;
+ $widget = $widget->changeType(TextFormat::class);
+ $widget->format = $items[$delta]->format ?? NULL;
+ $widget->base_type = $type;
if ($allowed_formats && !$this->isDefaultValueWidget($form_state)) {
- $element['#allowed_formats'] = $allowed_formats;
+ $widget->allowed_formats = $allowed_formats;
}
- return $element;
+ return $widget;
}
/**
diff --git a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
index 957b7ae5e9d..92576dcb95b 100644
--- a/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
+++ b/core/modules/text/tests/src/FunctionalJavascript/TextareaWithSummaryTest.php
@@ -7,12 +7,12 @@ namespace Drupal\Tests\text\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
+use PHPUnit\Framework\Attributes\Group;
/**
* Tests the JavaScript functionality of the text_textarea_with_summary widget.
- *
- * @group text
*/
+#[Group('text')]
class TextareaWithSummaryTest extends WebDriverTestBase {
/**