diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml index 93a349451693..60f34c34f0fb 100644 --- a/core/config/schema/core.entity.schema.yml +++ b/core/config/schema/core.entity.schema.yml @@ -130,7 +130,7 @@ entity_form_display.field.*: type: entity_field_form_display_base label: 'Entity form display default' -entity_form_display.field.string: +entity_form_display.field.string_textfield: type: entity_field_form_display_base label: 'Text field display format settings' mapping: diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php index 59c08e24a189..cac0ca18738d 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php @@ -12,6 +12,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; /** @@ -19,10 +20,9 @@ use Drupal\Core\TypedData\DataDefinition; * * @FieldType( * id = "string", - * label = @Translation("String"), - * description = @Translation("An entity field containing a string value."), - * no_ui = TRUE, - * default_widget = "string", + * label = @Translation("Text (plain)"), + * description = @Translation("A field containing a plain string value."), + * default_widget = "string_textfield", * default_formatter = "string" * ) */ @@ -95,4 +95,23 @@ class StringItem extends FieldItemBase { return $values; } + /** + * {@inheritdoc} + */ + public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { + $element = array(); + + $element['max_length'] = array( + '#type' => 'number', + '#title' => t('Maximum length'), + '#default_value' => $this->getSetting('max_length'), + '#required' => TRUE, + '#description' => t('The maximum length of the field in characters.'), + '#min' => 1, + '#disabled' => $has_data, + ); + + return $element; + } + } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php index ec7928131ff3..30a9df0f34a3 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringLongItem.php @@ -14,11 +14,10 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; * * @FieldType( * id = "string_long", - * label = @Translation("Long string"), - * description = @Translation("An entity field containing a long string value."), + * label = @Translation("Text (plain, long)"), + * description = @Translation("A field containing a long string value."), * default_widget = "string_textarea", * default_formatter = "string", - * no_ui = TRUE * ) */ class StringLongItem extends StringItem { diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php similarity index 89% rename from core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringWidget.php rename to core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php index 853e66111db8..0ed4239cde30 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Field\Plugin\Field\FieldWidget\StringWidget. + * Contains \Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget. */ namespace Drupal\Core\Field\Plugin\Field\FieldWidget; @@ -12,17 +12,17 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; /** - * Plugin implementation of the 'string' widget. + * Plugin implementation of the 'string_textfield' widget. * * @FieldWidget( - * id = "string", - * label = @Translation("String field"), + * id = "string_textfield", + * label = @Translation("Textfield"), * field_types = { * "string" * } * ) */ -class StringWidget extends WidgetBase { +class StringTextfieldWidget extends WidgetBase { /** * {@inheritdoc} diff --git a/core/modules/aggregator/src/Entity/Feed.php b/core/modules/aggregator/src/Entity/Feed.php index a70647050a52..5a9317a56148 100644 --- a/core/modules/aggregator/src/Entity/Feed.php +++ b/core/modules/aggregator/src/Entity/Feed.php @@ -146,7 +146,7 @@ class Feed extends ContentEntityBase implements FeedInterface { ->setRequired(TRUE) ->setSetting('max_length', 255) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -5, )); diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index 01b49ec026a5..2d035ec6bfea 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -168,7 +168,7 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { ->setTranslatable(TRUE) ->setRequired(TRUE) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -5, )) ->setDisplayConfigurable('form', TRUE); diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index 5c76abb39df6..54dc128b77ff 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -234,7 +234,6 @@ class CommentManager implements CommentManagerInterface { 'label' => 'Comment', 'entity_type' => 'comment', 'bundle' => $comment_type_id, - 'settings' => array('text_processing' => 1), 'required' => TRUE, )); $field_instance->save(); diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 9823f9f9d9a5..b49d99367242 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -230,7 +230,7 @@ class Comment extends ContentEntityBase implements CommentInterface { ->setTranslatable(TRUE) ->setSetting('max_length', 64) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', // Default comment body field has weight 20. 'weight' => 10, )) diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php index 393bfd7d3944..cfbb1e7f51d9 100644 --- a/core/modules/comment/src/Tests/CommentFieldsTest.php +++ b/core/modules/comment/src/Tests/CommentFieldsTest.php @@ -114,24 +114,4 @@ class CommentFieldsTest extends CommentTestBase { $this->postComment($book_node, $this->randomMachineName(), $this->randomMachineName()); } - /** - * Tests that comment module works correctly with plain text format. - */ - function testCommentFormat() { - // Disable text processing for comments. - $this->drupalLogin($this->admin_user); - $edit = array('instance[settings][text_processing]' => 0); - $this->drupalPostForm('admin/structure/comment/manage/comment/fields/comment.comment.comment_body', $edit, t('Save settings')); - - // Change formatter settings. - $this->drupalGet('admin/structure/comment/manage/comment/display'); - $edit = array('fields[comment_body][type]' => 'text_trimmed', 'refresh_rows' => 'comment_body'); - $commands = $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh'))); - $this->assertTrue($commands, 'Ajax commands returned'); - - // Post a comment without an explicit subject. - $this->drupalLogin($this->web_user); - $edit = array('comment_body[0][value]' => $this->randomMachineName(8)); - $this->drupalPostForm('node/' . $this->node->id(), $edit, t('Save')); - } } diff --git a/core/modules/comment/src/Tests/CommentTestBase.php b/core/modules/comment/src/Tests/CommentTestBase.php index 05f139d6d3a3..7a0b5066a73b 100644 --- a/core/modules/comment/src/Tests/CommentTestBase.php +++ b/core/modules/comment/src/Tests/CommentTestBase.php @@ -218,7 +218,7 @@ abstract class CommentTestBase extends WebTestBase { $form_display = entity_get_form_display('comment', 'comment', 'default'); if ($enabled) { $form_display->setComponent('subject', array( - 'type' => 'string', + 'type' => 'string_textfield', )); } else { diff --git a/core/modules/contact/src/Entity/Message.php b/core/modules/contact/src/Entity/Message.php index 9d2269ef4eb3..bbccd1754bb8 100644 --- a/core/modules/contact/src/Entity/Message.php +++ b/core/modules/contact/src/Entity/Message.php @@ -162,7 +162,7 @@ class Message extends ContentEntityBase implements MessageInterface { ->setRequired(TRUE) ->setSetting('max_length', 100) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -10, )) ->setDisplayConfigurable('form', TRUE); diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php index f2fa13d6f378..9655e46eb7ff 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php @@ -180,7 +180,7 @@ abstract class ContentTranslationTestBase extends WebTestBase { } entity_create('field_storage_config', array( 'name' => $this->fieldName, - 'type' => 'text', + 'type' => 'string', 'entity_type' => $this->entityTypeId, 'cardinality' => 1, 'translatable' => TRUE, @@ -193,7 +193,7 @@ abstract class ContentTranslationTestBase extends WebTestBase { ))->save(); entity_get_form_display($this->entityTypeId, $this->bundle, 'default') ->setComponent($this->fieldName, array( - 'type' => 'text_textfield', + 'type' => 'string_textfield', 'weight' => 0, )) ->save(); diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 85f58fa47780..fec8a70ddd53 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -7,6 +7,7 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; @@ -396,7 +397,7 @@ function editor_entity_revision_delete(EntityInterface $entity) { } /** - * Records file usage of files referenced by processed text fields. + * Records file usage of files referenced by formatted text fields. * * Every referenced file that does not yet have the FILE_STATUS_PERMANENT state, * will be given that state. @@ -419,7 +420,7 @@ function _editor_record_file_usage(array $uuids, EntityInterface $entity) { } /** - * Deletes file usage of files referenced by processed text fields. + * Deletes file usage of files referenced by formatted text fields. * * @param array $uuids * An array of file entity UUIDs. @@ -440,7 +441,7 @@ function _editor_delete_file_usage(array $uuids, EntityInterface $entity, $count } /** - * Finds all files referenced (data-editor-file-uuid) by processed text fields. + * Finds all files referenced (data-editor-file-uuid) by formatted text fields. * * @param EntityInterface $entity * An entity whose fields to analyze. @@ -451,32 +452,32 @@ function _editor_delete_file_usage(array $uuids, EntityInterface $entity, $count function _editor_get_file_uuids_by_field(EntityInterface $entity) { $uuids = array(); - $processed_text_fields = _editor_get_processed_text_fields($entity); - foreach ($processed_text_fields as $processed_text_field) { - $text = $entity->get($processed_text_field)->value; - $uuids[$processed_text_field] = _editor_parse_file_uuids($text); + $formatted_text_fields = _editor_get_formatted_text_fields($entity); + foreach ($formatted_text_fields as $formatted_text_field) { + $text = $entity->get($formatted_text_field)->value; + $uuids[$formatted_text_field] = _editor_parse_file_uuids($text); } return $uuids; } /** - * Determines the text fields on an entity that have text processing enabled. + * Determines the formatted text fields on an entity. * - * @param EntityInterface $entity + * @param ContentEntityInterface $entity * An entity whose fields to analyze. * * @return array - * The names of the fields on this entity that have text processing enabled. + * The names of the fields on this entity that support formatted text. */ -function _editor_get_processed_text_fields(ContentEntityInterface $entity) { +function _editor_get_formatted_text_fields(ContentEntityInterface $entity) { $field_definitions = $entity->getFieldDefinitions(); if (empty($field_definitions)) { return array(); } - // Only return fields that have text processing enabled. - return array_keys(array_filter($field_definitions, function ($definition) { - return $definition->getSetting('text_processing') === TRUE; + // Only return formatted text fields. + return array_keys(array_filter($field_definitions, function (FieldDefinitionInterface $definition) { + return in_array($definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE); })); } diff --git a/core/modules/editor/js/editor.formattedTextEditor.js b/core/modules/editor/js/editor.formattedTextEditor.js index 29d7eb3782bf..1dd2c2143d8f 100644 --- a/core/modules/editor/js/editor.formattedTextEditor.js +++ b/core/modules/editor/js/editor.formattedTextEditor.js @@ -1,6 +1,6 @@ /** * @file - * Text editor-based in-place editor for processed text content in Drupal. + * Text editor-based in-place editor for formatted text content in Drupal. * * Depends on editor.module. Works with any (WYSIWYG) editor that implements the * editor.js API, including the optional attachInlineEditor() and onChange() @@ -78,9 +78,9 @@ break; case 'activating': - // When transformation filters have been been applied to the processed - // text of this field, then we'll need to load a re-processed version of - // it without the transformation filters. + // When transformation filters have been been applied to the formatted + // text of this field, then we'll need to load a re-formatted version + // of it without the transformation filters. if (this.textFormatHasTransformations) { var $textElement = this.$textElement; this._getUntransformedText(function (untransformedText) { @@ -151,7 +151,7 @@ /** * Loads untransformed text for this field. * - * More accurately: it re-processes processed text to exclude transformation + * More accurately: it re-filters formatted text to exclude transformation * filters used by the text format. * * @param Function callback diff --git a/core/modules/editor/src/Ajax/GetUntransformedTextCommand.php b/core/modules/editor/src/Ajax/GetUntransformedTextCommand.php index 99f8d4e027dc..3465729603a7 100644 --- a/core/modules/editor/src/Ajax/GetUntransformedTextCommand.php +++ b/core/modules/editor/src/Ajax/GetUntransformedTextCommand.php @@ -11,7 +11,7 @@ use Drupal\Core\Ajax\CommandInterface; use Drupal\quickedit\Ajax\BaseCommand; /** - * AJAX command to rerender a processed text field without any transformation + * AJAX command to rerender a formatted text field without any transformation * filters. */ class GetUntransformedTextCommand extends BaseCommand { diff --git a/core/modules/editor/src/EditorController.php b/core/modules/editor/src/EditorController.php index e5a768eac4c7..44feda30f836 100644 --- a/core/modules/editor/src/EditorController.php +++ b/core/modules/editor/src/EditorController.php @@ -29,15 +29,15 @@ class EditorController extends ControllerBase { /** * Returns an Ajax response to render a text field without transformation filters. * - * @param int $entity - * The entity of which a processed text field is being rerendered. + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity of which a formatted text field is being rerendered. * @param string $field_name - * The name of the (processed text) field that that is being rerendered + * The name of the (formatted text) field that that is being rerendered * @param string $langcode - * The name of the language for which the processed text field is being - * rererendered. + * The name of the language for which the formatted text field is being + * rerendered. * @param string $view_mode_id - * The view mode the processed text field should be rerendered in. + * The view mode the formatted text field should be rerendered in. * * @return \Drupal\Core\Ajax\AjaxResponse * The Ajax response. diff --git a/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php b/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php index d729943b32b8..d56cfffdc523 100644 --- a/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php +++ b/core/modules/editor/src/Plugin/InPlaceEditor/Editor.php @@ -32,10 +32,10 @@ class Editor extends PluginBase implements InPlaceEditorInterface { if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) { return FALSE; } - // This editor is compatible with processed ("rich") text fields; but only + // This editor is compatible with formatted ("rich") text fields; but only // if there is a currently active text format, that text format has an // associated editor and that editor supports inline editing. - elseif ($field_definition->getSetting('text_processing')) { + elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) { if ($editor = editor_load($items[0]->format)) { $definition = \Drupal::service('plugin.manager.editor')->getDefinition($editor->getEditor()); if ($definition['supports_inline_editing'] === TRUE) { diff --git a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php index 2ba6aff4944b..7e28a446c723 100644 --- a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php +++ b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php @@ -75,7 +75,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase { $this->createFieldWithInstance( $this->field_name, 'text', 1, 'Long text field', // Instance settings. - array('text_processing' => 1), + array(), // Widget type & settings. 'text_textarea', array('size' => 42), @@ -122,7 +122,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase { /** * Tests editor selection when the Editor module is present. * - * Tests a textual field, with text processing, with cardinality 1 and >1, + * Tests a textual field, with text filtering, with cardinality 1 and >1, * always with a ProcessedTextEditor plug-in present, but with varying text * format compatibility. */ diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php index 2a202909e86f..33b4af0ea047 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php @@ -69,9 +69,6 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase { 'bundle' => $this->bundle, 'field_name' => 'body', 'label' => 'Body', - 'settings' => array( - 'text_processing' => TRUE, - ), ))->save(); entity_get_display($this->entityType, $this->bundle, 'default') ->setComponent('body', array( diff --git a/core/modules/field/src/Tests/String/StringFormatterTest.php b/core/modules/field/src/Tests/String/StringFormatterTest.php new file mode 100644 index 000000000000..2488f73b4161 --- /dev/null +++ b/core/modules/field/src/Tests/String/StringFormatterTest.php @@ -0,0 +1,127 @@ +installConfig(array('system', 'field')); + $this->installEntitySchema('entity_test'); + + $this->entityType = 'entity_test'; + $this->bundle = $this->entityType; + $this->fieldName = Unicode::strtolower($this->randomMachineName()); + + $field_storage = FieldStorageConfig::create(array( + 'name' => $this->fieldName, + 'entity_type' => $this->entityType, + 'type' => 'string', + )); + $field_storage->save(); + + $instance = FieldInstanceConfig::create(array( + 'field_storage' => $field_storage, + 'bundle' => $this->bundle, + 'label' => $this->randomMachineName(), + )); + $instance->save(); + + $this->display = entity_get_display($this->entityType, $this->bundle, 'default') + ->setComponent($this->fieldName, array( + 'type' => 'string', + 'settings' => array(), + )); + $this->display->save(); + } + + /** + * Renders fields of a given entity with a given display. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * The entity object with attached fields to render. + * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display + * The display to render the fields in. + * + * @return string + * The rendered entity fields. + */ + protected function renderEntityFields(ContentEntityInterface $entity, EntityViewDisplayInterface $display) { + $content = $display->build($entity); + $content = $this->render($content); + return $content; + } + + /** + * Tests string formatter output. + */ + public function testStringFormatter() { + $value = $this->randomString(); + $value .= "\n\n" . $this->randomString() . ''; + $value .= "\n\n" . $this->randomString(); + + $entity = EntityTest::create(array()); + $entity->{$this->fieldName}->value = $value; + + // Verify that all HTML is escaped and newlines are retained. + $this->renderEntityFields($entity, $this->display); + $this->assertNoRaw($value); + $this->assertRaw(nl2br(String::checkPlain($value))); + + // Verify the cache tags. + $build = $entity->{$this->fieldName}->view(); + $this->assertTrue(!isset($build[0]['#cache']), format_string('The string formatter has no cache tags.')); + } + +} diff --git a/core/modules/field/src/Tests/Views/FieldTestBase.php b/core/modules/field/src/Tests/Views/FieldTestBase.php index 43222e04bde9..204b0371b4e8 100644 --- a/core/modules/field/src/Tests/Views/FieldTestBase.php +++ b/core/modules/field/src/Tests/Views/FieldTestBase.php @@ -61,7 +61,7 @@ abstract class FieldTestBase extends ViewTestBase { ViewTestData::createTestViews(get_class($this), array('field_test_views')); } - function setUpFields($amount = 3) { + function setUpFields($amount = 3, $type = 'string') { // Create three fields. $field_names = array(); for ($i = 0; $i < $amount; $i++) { @@ -69,7 +69,7 @@ abstract class FieldTestBase extends ViewTestBase { $this->fieldStorages[$i] = entity_create('field_storage_config', array( 'name' => $field_names[$i], 'entity_type' => 'node', - 'type' => 'text', + 'type' => $type, )); $this->fieldStorages[$i]->save(); } diff --git a/core/modules/field/src/Tests/Views/FieldUITest.php b/core/modules/field/src/Tests/Views/FieldUITest.php index c38aaee2e629..77b3b7f4f2e7 100644 --- a/core/modules/field/src/Tests/Views/FieldUITest.php +++ b/core/modules/field/src/Tests/Views/FieldUITest.php @@ -47,7 +47,7 @@ class FieldUITest extends FieldTestBase { $this->account = $this->drupalCreateUser(array('administer views')); $this->drupalLogin($this->account); - $this->setUpFields(); + $this->setUpFields(1, 'text'); $this->setUpInstances(); } @@ -65,7 +65,7 @@ class FieldUITest extends FieldTestBase { }, $result); // @todo Replace this sort by assertArray once it's in. sort($options, SORT_STRING); - $this->assertEqual($options, array('string', 'text_default', 'text_trimmed'), 'The text formatters for a simple text field appear as expected.'); + $this->assertEqual($options, array('text_default', 'text_trimmed'), 'The text formatters for a simple text field appear as expected.'); $this->drupalPostForm(NULL, array('options[type]' => 'text_trimmed'), t('Apply')); diff --git a/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php index e575a029d9ba..bf03f16c5384 100644 --- a/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/src/Tests/Views/HandlerFieldFieldTest.php @@ -45,7 +45,7 @@ class HandlerFieldFieldTest extends FieldTestBase { $this->fieldStorages[3] = entity_create('field_storage_config', array( 'name' => 'field_name_3', 'entity_type' => 'node', - 'type' => 'text', + 'type' => 'string', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, )); $this->fieldStorages[3]->save(); @@ -53,11 +53,19 @@ class HandlerFieldFieldTest extends FieldTestBase { $this->fieldStorages[4] = entity_create('field_storage_config', array( 'name' => 'field_name_4', 'entity_type' => 'node', - 'type' => 'text', + 'type' => 'string', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, )); $this->fieldStorages[4]->save(); + // Setup a text field. + $this->fieldStorages[5] = entity_create('field_storage_config', array( + 'name' => 'field_name_5', + 'entity_type' => 'node', + 'type' => 'text', + )); + $this->fieldStorages[5]->save(); + $this->setUpInstances(); // Create some nodes. @@ -65,7 +73,7 @@ class HandlerFieldFieldTest extends FieldTestBase { for ($i = 0; $i < 3; $i++) { $edit = array('type' => 'page'); - for ($key = 0; $key < 3; $key++) { + foreach (array(0, 1, 2, 5) as $key) { $field_storage = $this->fieldStorages[$key]; $edit[$field_storage->getName()][0]['value'] = $this->randomMachineName(8); } @@ -125,8 +133,8 @@ class HandlerFieldFieldTest extends FieldTestBase { public function _testFormatterSimpleFieldRender() { $view = Views::getView('test_view_fieldapi'); $this->prepareView($view); - $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[0]->getName()]['type'] = 'text_trimmed'; - $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[0]->getName()]['settings'] = array( + $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[5]->getName()]['type'] = 'text_trimmed'; + $view->displayHandlers->get('default')->options['fields'][$this->fieldStorages[5]->getName()]['settings'] = array( 'trim_length' => 3, ); $this->executeView($view); @@ -134,8 +142,8 @@ class HandlerFieldFieldTest extends FieldTestBase { // Make sure that the formatter works as expected. // @TODO: actually there should be a specific formatter. for ($i = 0; $i < 2; $i++) { - $rendered_field = $view->style_plugin->getField($i, $this->fieldStorages[0]->getName()); - $this->assertEqual(strlen($rendered_field), 3); + $rendered_field = $view->style_plugin->getField($i, $this->fieldStorages[5]->getName()); + $this->assertEqual(strlen(html_entity_decode($rendered_field)), 3); } } diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml index b5df1dc1f190..a9ef175c11d4 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import.yml @@ -8,8 +8,7 @@ description: '' required: false default_value: { } default_value_function: '' -settings: - text_processing: 0 +settings: { } field_type: text dependencies: entity: diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml index 2d482a52e321..6c359e2bbb0f 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.entity_test.field_test_import_2.yml @@ -8,8 +8,7 @@ description: '' required: false default_value: { } default_value_function: '' -settings: - text_processing: 0 +settings: { } field_type: text dependencies: entity: diff --git a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml index 50f76c152075..7d63acb32d73 100644 --- a/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml +++ b/core/modules/field/tests/modules/field_test_config/config/install/field.instance.entity_test.test_bundle.field_test_import_2.yml @@ -8,8 +8,7 @@ description: '' required: false default_value: { } default_value_function: '' -settings: - text_processing: 0 +settings: { } field_type: text dependencies: entity: diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml index c69e8bab8c5b..9a088dd789f6 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.entity_test.field_test_import_staging.yml @@ -9,8 +9,7 @@ description: '' required: '0' default_value: { } default_value_function: '' -settings: - text_processing: '0' +settings: { } field_type: text dependencies: entity: diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml index 2bf3bb7fbb4e..cc8ccd4530a6 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle.field_test_import_staging_2.yml @@ -9,8 +9,7 @@ description: '' required: '0' default_value: { } default_value_function: '' -settings: - text_processing: '0' +settings: { } field_type: text dependencies: entity: diff --git a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml index 9e04777c1310..f58572a6a666 100644 --- a/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml +++ b/core/modules/field/tests/modules/field_test_config/staging/field.instance.entity_test.test_bundle_2.field_test_import_staging_2.yml @@ -9,8 +9,7 @@ description: '' required: '0' default_value: { } default_value_function: '' -settings: - text_processing: '0' +settings: { } field_type: text dependencies: entity: diff --git a/core/modules/field/tests/modules/field_test_views/test_views/views.view.test_view_fieldapi.yml b/core/modules/field/tests/modules/field_test_views/test_views/views.view.test_view_fieldapi.yml index 275aefbf108b..8ad5a080a882 100644 --- a/core/modules/field/tests/modules/field_test_views/test_views/views.view.test_view_fieldapi.yml +++ b/core/modules/field/tests/modules/field_test_views/test_views/views.view.test_view_fieldapi.yml @@ -20,6 +20,12 @@ display: field: field_name_0 plugin_id: field provider: field + field_name_5: + id: field_name_5 + table: node__field_name_5 + field: field_name_5 + plugin_id: field + provider: field cache: type: none exposed_form: diff --git a/core/modules/forum/config/install/core.entity_form_display.taxonomy_term.forums.default.yml b/core/modules/forum/config/install/core.entity_form_display.taxonomy_term.forums.default.yml index d295232be240..4e13510fbb62 100644 --- a/core/modules/forum/config/install/core.entity_form_display.taxonomy_term.forums.default.yml +++ b/core/modules/forum/config/install/core.entity_form_display.taxonomy_term.forums.default.yml @@ -5,7 +5,7 @@ mode: default status: true content: name: - type: string + type: string_textfield weight: -5 settings: size: 60 diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index ea3cc30a3b8d..c39d156f6e29 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -293,7 +293,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf 'weight' => -5, )) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -5, )) ->setDisplayConfigurable('form', TRUE); @@ -311,7 +311,7 @@ class MenuLinkContent extends ContentEntityBase implements MenuLinkContentInterf 'weight' => 0, )) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => 0, )); diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/FieldInstanceSettings.php b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/FieldInstanceSettings.php index c144ef49065e..a16a73912397 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/FieldInstanceSettings.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/process/d6/FieldInstanceSettings.php @@ -26,10 +26,6 @@ class FieldInstanceSettings extends ProcessPluginBase { list($widget_type, $widget_settings, $field_settings) = $value; $settings = array(); switch ($widget_type) { - case 'text_textfield': - $settings['text_processing'] = $field_settings['text_processing']; - break; - case 'number': $settings['min'] = $field_settings['min']; $settings['max'] = $field_settings['max']; diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php index d154214c22ca..0aefcc7a624a 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldInstanceTest.php @@ -85,7 +85,7 @@ class MigrateFieldInstanceTest extends MigrateDrupalTestBase { // Test a text field. $field = entity_load('field_instance_config', 'node.story.field_test'); $this->assertEqual($field->label(), 'Text Field'); - $expected = array('max_length' => 255, 'text_processing' => 1); + $expected = array('max_length' => 255); $this->assertEqual($field->getSettings(), $expected); $this->assertEqual('text for default value', $entity->field_test->value); diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 4e0f300ab4b5..e5097bfa1c6d 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -153,7 +153,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr $length = $settings['trim_length']; } - $output = text_summary($output, $field_definition->getSetting('text_processing') ? $item->format : NULL, $length); + $output = text_summary($output, $item->format, $length); } } $replacements[$original] = $output; diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 037475b8d0ab..ef8c23b6159d 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -366,7 +366,7 @@ class Node extends ContentEntityBase implements NodeInterface { 'weight' => -5, )) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -5, )) ->setDisplayConfigurable('form', TRUE); diff --git a/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php index bbba4e91bb9c..15c632852d28 100644 --- a/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/src/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -44,9 +44,6 @@ class MultiStepNodeFormBasicOptionsTest extends NodeTestBase { 'entity_type' => 'node', 'bundle' => 'page', 'label' => $this->randomMachineName() . '_label', - 'settings' => array( - 'text_processing' => TRUE, - ), ))->save(); entity_get_form_display('node', 'page', 'default') ->setComponent($this->field_name, array( diff --git a/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php b/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php index 3938ce90f9d0..4b24ac8a29d4 100644 --- a/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php +++ b/core/modules/quickedit/src/Plugin/InPlaceEditor/PlainTextEditor.php @@ -21,9 +21,6 @@ class PlainTextEditor extends InPlaceEditorBase { /** * {@inheritdoc} - * - * @todo The processed text logic is too coupled to text fields. Figure out - * how to generalize to other textual field types. */ public function isCompatible(FieldItemListInterface $items) { $field_definition = $items->getFieldDefinition(); @@ -32,8 +29,8 @@ class PlainTextEditor extends InPlaceEditorBase { if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) { return FALSE; } - // This editor is incompatible with processed ("rich") text fields. - elseif ($field_definition->getSetting('text_processing')) { + // This editor is incompatible with formatted ("rich") text fields. + elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) { return FALSE; } else { diff --git a/core/modules/quickedit/src/Tests/EditorSelectionTest.php b/core/modules/quickedit/src/Tests/EditorSelectionTest.php index 10bf38b1fb38..380c934497ad 100644 --- a/core/modules/quickedit/src/Tests/EditorSelectionTest.php +++ b/core/modules/quickedit/src/Tests/EditorSelectionTest.php @@ -8,7 +8,6 @@ namespace Drupal\quickedit\Tests; use Drupal\Core\Language\LanguageInterface; -use Drupal\quickedit\Plugin\InPlaceEditorManager; use Drupal\quickedit\EditorSelector; /** @@ -50,57 +49,41 @@ class EditorSelectionTest extends QuickEditTestBase { } /** - * Tests a textual field, without/with text processing, with cardinality 1 and - * >1, always without a WYSIWYG editor present. + * Tests a string (plain text) field, with cardinality 1 and >1. */ public function testText() { $field_name = 'field_text'; $this->createFieldWithInstance( - $field_name, 'text', 1, 'Simple text field', + $field_name, 'string', 1, 'Plain text field', // Instance settings. - array('text_processing' => 0), + array(), // Widget type & settings. - 'text_textfield', + 'string', array('size' => 42), // 'default' formatter type & settings. - 'text_default', + 'string', array() ); // Create an entity with values for this text field. $entity = entity_create('entity_test'); $entity->{$field_name}->value = 'Hello, world!'; - $entity->{$field_name}->format = 'full_html'; $entity->save(); - // Editor selection without text processing, with cardinality 1. - $this->assertEqual('plain_text', $this->getSelectedEditor($entity->id(), $field_name), "Without text processing, cardinality 1, the 'plain_text' editor is selected."); + // With cardinality 1. + $this->assertEqual('plain_text', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality 1, the 'plain_text' editor is selected."); - // Editor selection with text processing, cardinality 1. - $this->fields->field_text_instance->settings['text_processing'] = 1; - $this->fields->field_text_instance->save(); - $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With text processing, cardinality 1, the 'form' editor is selected."); - - // Editor selection without text processing, cardinality 1 (again). - $this->fields->field_text_instance->settings['text_processing'] = 0; - $this->fields->field_text_instance->save(); - $this->assertEqual('plain_text', $this->getSelectedEditor($entity->id(), $field_name), "Without text processing again, cardinality 1, the 'plain_text' editor is selected."); - - // Editor selection without text processing, cardinality >1 + // With cardinality >1 $this->fields->field_text_field_storage->cardinality = 2; $this->fields->field_text_field_storage->save(); - $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "Without text processing, cardinality >1, the 'form' editor is selected."); + $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality >1, the 'form' editor is selected."); - // Editor selection with text processing, cardinality >1 - $this->fields->field_text_instance->settings['text_processing'] = 1; - $this->fields->field_text_instance->save(); - $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With text processing, cardinality >1, the 'form' editor is selected."); } /** - * Tests a textual field, with text processing, with cardinality 1 and >1, + * Tests a textual field, with text filtering, with cardinality 1 and >1, * always with an Editor plugin present that supports textual fields with text - * processing, but with varying text format compatibility. + * filtering, but with varying text format compatibility. */ public function testTextWysiwyg() { // Enable edit_test module so that the 'wysiwyg' editor becomes available. @@ -112,7 +95,7 @@ class EditorSelectionTest extends QuickEditTestBase { $this->createFieldWithInstance( $field_name, 'text', 1, 'Long text field', // Instance settings. - array('text_processing' => 1), + array(), // Widget type & settings. 'text_textarea', array('size' => 42), @@ -135,7 +118,7 @@ class EditorSelectionTest extends QuickEditTestBase { $entity->save(); $this->assertEqual('wysiwyg', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected."); - // Editor selection with text processing, cardinality >1 + // Editor selection with text field, cardinality >1. $this->fields->field_textarea_field_storage->cardinality = 2; $this->fields->field_textarea_field_storage->save(); $this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected."); diff --git a/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php b/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php index bf1df1475f72..19f9c9ed5f5b 100644 --- a/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php +++ b/core/modules/quickedit/src/Tests/MetadataGeneratorTest.php @@ -67,16 +67,16 @@ class MetadataGeneratorTest extends QuickEditTestBase { */ public function testSimpleEntityType() { $field_1_name = 'field_text'; - $field_1_label = 'Simple text field'; + $field_1_label = 'Plain text field'; $this->createFieldWithInstance( - $field_1_name, 'text', 1, $field_1_label, + $field_1_name, 'string', 1, $field_1_label, // Instance settings. - array('text_processing' => 0), + array(), // Widget type & settings. - 'text_textfield', + 'string', array('size' => 42), // 'default' formatter type & settings. - 'text_default', + 'string', array() ); $field_2_name = 'field_nr'; @@ -105,9 +105,9 @@ class MetadataGeneratorTest extends QuickEditTestBase { $metadata_1 = $this->metadataGenerator->generateFieldMetadata($items_1, 'default'); $expected_1 = array( 'access' => TRUE, - 'label' => 'Simple text field', + 'label' => 'Plain text field', 'editor' => 'plain_text', - 'aria' => 'Entity entity_test 1, field Simple text field', + 'aria' => 'Entity entity_test 1, field Plain text field', ); $this->assertEqual($expected_1, $metadata_1, 'The correct metadata is generated for the first field.'); @@ -143,7 +143,7 @@ class MetadataGeneratorTest extends QuickEditTestBase { $this->createFieldWithInstance( $field_name, 'text', 1, $field_label, // Instance settings. - array('text_processing' => 1), + array(), // Widget type & settings. 'text_textfield', array('size' => 42), diff --git a/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php b/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php index 21c88b493d97..8727b63f4f72 100644 --- a/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php +++ b/core/modules/quickedit/tests/modules/src/Plugin/InPlaceEditor/WysiwygEditor.php @@ -30,10 +30,10 @@ class WysiwygEditor extends InPlaceEditorBase { if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) { return FALSE; } - // This editor is compatible with processed ("rich") text fields; but only + // This editor is compatible with formatted ("rich") text fields; but only // if there is a currently active text format and that text format is the // 'full_html' text format. - elseif ($field_definition->getSetting('text_processing')) { + elseif (in_array($field_definition->getType(), array('text', 'text_long', 'text_with_summary'), TRUE)) { if ($items[0]->format === 'full_html') { return TRUE; } diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php b/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php index 98fa3b525fab..0b43c30dd8f7 100644 --- a/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php +++ b/core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php @@ -28,6 +28,8 @@ class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase { $this->createTestField(); + $this->installConfig(array('filter')); + // Add the mapping. $mapping = rdf_get_mapping('entity_test', 'entity_test'); $mapping->setFieldMapping($this->fieldName, array( diff --git a/core/modules/rdf/src/Tests/Field/StringFieldRdfaTest.php b/core/modules/rdf/src/Tests/Field/StringFieldRdfaTest.php new file mode 100644 index 000000000000..92be1d61ac5f --- /dev/null +++ b/core/modules/rdf/src/Tests/Field/StringFieldRdfaTest.php @@ -0,0 +1,59 @@ +createTestField(); + + // Add the mapping. + $mapping = rdf_get_mapping('entity_test', 'entity_test'); + $mapping->setFieldMapping($this->fieldName, array( + 'properties' => array('schema:text'), + ))->save(); + + // Set up test entity. + $this->entity = entity_create('entity_test'); + $this->entity->{$this->fieldName}->value = $this->testValue; + $this->entity->{$this->fieldName}->summary = $this->testSummary; + } + + /** + * Tests string formatters. + */ + public function testStringFormatters() { + // Tests the string formatter. + $this->assertFormatterRdfa(array('type'=>'string'), 'http://schema.org/text', array('value' => $this->testValue)); + } +} diff --git a/core/modules/rdf/src/Tests/Field/TextFieldRdfaTest.php b/core/modules/rdf/src/Tests/Field/TextFieldRdfaTest.php index 291301fcbf04..e0d36b952825 100644 --- a/core/modules/rdf/src/Tests/Field/TextFieldRdfaTest.php +++ b/core/modules/rdf/src/Tests/Field/TextFieldRdfaTest.php @@ -6,6 +6,7 @@ namespace Drupal\rdf\Tests\Field; +use Drupal\Component\Utility\String; use Drupal\rdf\Tests\Field\FieldRdfaTestBase; /** @@ -42,6 +43,8 @@ class TextFieldRdfaTest extends FieldRdfaTestBase { protected function setUp() { parent::setUp(); + $this->installConfig(array('filter')); + $this->createTestField(); // Add the mapping. @@ -62,13 +65,13 @@ class TextFieldRdfaTest extends FieldRdfaTestBase { * @todo Check for the summary mapping. */ public function testAllFormatters() { + $formatted_value = strip_tags($this->entity->{$this->fieldName}->processed); + // Tests the default formatter. - $this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/text', array('value' => $this->testValue)); - // Tests the plain formatter. - $this->assertFormatterRdfa(array('type'=>'string'), 'http://schema.org/text', array('value' => $this->testValue)); + $this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/text', array('value' => $formatted_value)); // Tests the summary formatter. - $this->assertFormatterRdfa(array('type'=>'text_summary_or_trimmed'), 'http://schema.org/text', array('value' => $this->testValue)); + $this->assertFormatterRdfa(array('type'=>'text_summary_or_trimmed'), 'http://schema.org/text', array('value' => $formatted_value)); // Tests the trimmed formatter. - $this->assertFormatterRdfa(array('type'=>'text_trimmed'), 'http://schema.org/text', array('value' => $this->testValue)); + $this->assertFormatterRdfa(array('type'=>'text_trimmed'), 'http://schema.org/text', array('value' => $formatted_value)); } } diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index e6fcf4969f48..a3e15e7d3c27 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -184,7 +184,7 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface { ->setDefaultValue('') ->setSetting('max_length', 255) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -10, 'settings' => array( 'size' => 40, diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php index 6cd695bce448..69712c38fcf3 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php @@ -127,7 +127,7 @@ class SimpleTestBrowserTest extends WebTestBase { $this->drupalGet('admin/config/development/testing'); $edit = array( // A KernalTestBase test. - 'tests[Drupal\text\Tests\Formatter\TextPlainUnitTest]' => TRUE, + 'tests[Drupal\field\Tests\String\StringFormatterTest]' => TRUE, ); $this->drupalPostForm(NULL, $edit, t('Run tests')); $this->assertText('0 fails, 0 exceptions'); diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php index c69d2cf45f4d..5474981b95d2 100644 --- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php @@ -683,11 +683,6 @@ class EntityFieldTest extends EntityUnitTestBase { * The entity type to run the tests with. */ protected function assertComputedProperties($entity_type) { - // Make the test text field processed. - $instance = FieldInstanceConfig::loadByName($entity_type, $entity_type, 'field_test_text'); - $instance->settings['text_processing'] = 1; - $instance->save(); - $entity = $this->createTestEntity($entity_type); $entity->field_test_text->value = "The text text to filter."; $entity->field_test_text->format = filter_default_format(); diff --git a/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php b/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php index 28fb33fab310..656d8c94d3f0 100644 --- a/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php +++ b/core/modules/system/src/Tests/Entity/EntityViewControllerTest.php @@ -90,7 +90,7 @@ class EntityViewControllerTest extends WebTestBase { // Browse to the entity and verify that the attribute is rendered in the // field item HTML markup. $this->drupalGet('entity_test/' . $entity->id()); - $xpath = $this->xpath('//div[@data-field-item-attr="foobar" and text()=:value]', array(':value' => $test_value)); + $xpath = $this->xpath('//div[@data-field-item-attr="foobar"]/p[text()=:value]', array(':value' => $test_value)); $this->assertTrue($xpath, 'The field item attribute has been found in the rendered output of the field.'); // Enable the RDF module to ensure that two modules can add attributes to @@ -107,7 +107,7 @@ class EntityViewControllerTest extends WebTestBase { // Browse to the entity and verify that the attributes from both modules // are rendered in the field item HTML markup. $this->drupalGet('entity_test/' . $entity->id()); - $xpath = $this->xpath('//div[@data-field-item-attr="foobar" and @property="schema:text" and text()=:value]', array(':value' => $test_value)); + $xpath = $this->xpath('//div[@data-field-item-attr="foobar" and @property="schema:text"]/p[text()=:value]', array(':value' => $test_value)); $this->assertTrue($xpath, 'The field item attributes from both modules have been found in the rendered output of the field.'); } diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index cf7e59847a88..fda4f52f4ee8 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -134,7 +134,7 @@ class Term extends ContentEntityBase implements TermInterface { 'weight' => -5, )) ->setDisplayOptions('form', array( - 'type' => 'string', + 'type' => 'string_textfield', 'weight' => -5, )) ->setDisplayConfigurable('form', TRUE); @@ -143,7 +143,6 @@ class Term extends ContentEntityBase implements TermInterface { ->setLabel(t('Description')) ->setDescription(t('A description of the term.')) ->setTranslatable(TRUE) - ->setSetting('text_processing', 1) ->setDisplayOptions('view', array( 'label' => 'hidden', 'type' => 'text_default', diff --git a/core/modules/text/config/schema/text.schema.yml b/core/modules/text/config/schema/text.schema.yml index dc54670904d3..b41705c6ca83 100644 --- a/core/modules/text/config/schema/text.schema.yml +++ b/core/modules/text/config/schema/text.schema.yml @@ -10,7 +10,7 @@ text.settings: field.text.settings: type: mapping - label: 'Text settings' + label: 'Text (formatted) settings' mapping: max_length: type: integer @@ -18,11 +18,9 @@ field.text.settings: field.text.instance_settings: type: mapping - label: 'Text settings' - mapping: - text_processing: - type: integer - label: 'Text processing' + label: 'Text (formatted) settings' + sequence: + - type: string field.text.value: type: sequence @@ -39,18 +37,14 @@ field.text.value: label: 'Text format' field.text_long.settings: - type: sequence - label: 'Settings' - sequence: - - type: string + label: 'Text (formatted, long) settings' + type: mapping + mapping: { } field.text_long.instance_settings: + label: 'Text (formatted, long) settings' type: mapping - label: 'Long text settings' - mapping: - text_processing: - type: string - label: 'Text processing' + mapping: { } field.text_long.value: type: sequence @@ -67,18 +61,14 @@ field.text_long.value: label: 'Text format' field.text_with_summary.settings: - type: sequence - label: 'Default' - sequence: - - type: string + label: 'Text (formatted, long, with summary) settings' + type: mapping + mapping: { } field.text_with_summary.instance_settings: type: mapping - label: 'Text area with a summary' + label: 'Text (formatted, long, with summary) settings' mapping: - text_processing: - type: boolean - label: 'Text processing' display_summary: type: boolean label: 'Summary input' @@ -102,7 +92,7 @@ field.text_with_summary.value: entity_view_display.field.text_default: type: entity_field_view_display_base - label: 'Text default display format settings' + label: 'Formatted text default display format settings' mapping: settings: type: sequence @@ -112,7 +102,7 @@ entity_view_display.field.text_default: entity_view_display.field.text_summary_or_trimmed: type: entity_field_view_display_base - label: 'Summary or trimmed text display format settings' + label: 'Summary or trimmed formatted text display format settings' mapping: settings: type: mapping diff --git a/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php index efdc29e7d3e0..efc4c0d5b049 100644 --- a/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.php @@ -32,25 +32,6 @@ class TextDefaultFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { - if ($this->getFieldSetting('text_processing')) { - return $this->viewElementsWithTextProcessing($items); - } - else { - return $this->viewElementsWithoutTextProcessing($items); - } - } - - /** - * Builds a renderable array when text processing is enabled. - * - * @param \Drupal\Core\Field\FieldItemListInterface $items - * The text field values to be rendered. - * - * @return array - * A renderable array for $items, as an array of child elements keyed by - * consecutive numeric indexes starting from 0. - */ - protected function viewElementsWithTextProcessing(FieldItemListInterface $items) { $elements = array(); foreach ($items as $delta => $item) { @@ -65,26 +46,4 @@ class TextDefaultFormatter extends FormatterBase { return $elements; } - /** - * Builds a renderable array when text processing is disabled. - * - * @param \Drupal\Core\Field\FieldItemListInterface $items - * The text field values to be rendered. - * - * @return array - * A renderable array for $items, as an array of child elements keyed by - * consecutive numeric indexes starting from 0. - */ - protected function viewElementsWithoutTextProcessing(FieldItemListInterface $items) { - $elements = array(); - - foreach ($items as $delta => $item) { - $elements[$delta] = array( - '#markup' => $item->processed, - ); - } - - return $elements; - } - } diff --git a/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php b/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php index 39739526082f..ed1c8c3ae125 100644 --- a/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php @@ -69,25 +69,6 @@ class TextTrimmedFormatter extends FormatterBase { * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { - if ($this->getFieldSetting('text_processing')) { - return $this->viewElementsWithTextProcessing($items); - } - else { - return $this->viewElementsWithoutTextProcessing($items); - } - } - - /** - * Builds a renderable array when text processing is enabled. - * - * @param \Drupal\Core\Field\FieldItemListInterface $items - * The text field values to be rendered. - * - * @return array - * A renderable array for $items, as an array of child elements keyed by - * consecutive numeric indexes starting from 0. - */ - protected function viewElementsWithTextProcessing(FieldItemListInterface $items) { $elements = array(); $render_as_summary = function (&$element) { @@ -120,35 +101,6 @@ class TextTrimmedFormatter extends FormatterBase { return $elements; } - /** - * Builds a renderable array when text processing is disabled. - * - * @param \Drupal\Core\Field\FieldItemListInterface $items - * The text field values to be rendered. - * - * @return array - * A renderable array for $items, as an array of child elements keyed by - * consecutive numeric indexes starting from 0. - */ - protected function viewElementsWithoutTextProcessing(FieldItemListInterface $items) { - $elements = array(); - - foreach ($items as $delta => $item) { - if ($this->getPluginId() == 'text_summary_or_trimmed' && !empty($item->summary)) { - $output = $item->summary_processed; - } - else { - $output = text_summary($item->processed, NULL, $this->getSetting('trim_length')); - } - - $elements[$delta] = array( - '#markup' => $output, - ); - } - - return $elements; - } - /** * Pre-render callback: Renders a processed text element's #markup as a summary. * diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php index 3b7285d4e327..6c32f08fbb7e 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextItem.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php @@ -15,8 +15,8 @@ use Drupal\Core\Form\FormStateInterface; * * @FieldType( * id = "text", - * label = @Translation("Text"), - * description = @Translation("This field stores varchar text in the database."), + * label = @Translation("Text (formatted)"), + * description = @Translation("This field stores a text with a text format."), * default_widget = "text_textfield", * default_formatter = "text_default" * ) @@ -95,23 +95,4 @@ class TextItem extends TextItemBase { return $element; } - /** - * {@inheritdoc} - */ - public function instanceSettingsForm(array $form, FormStateInterface $form_state) { - $element = array(); - - $element['text_processing'] = array( - '#type' => 'radios', - '#title' => t('Text processing'), - '#default_value' => $this->getSetting('text_processing'), - '#options' => array( - t('Plain text'), - t('Filtered text (user selects text format)'), - ), - ); - - return $element; - } - } diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php index 8b70203d2300..57603c13a352 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php @@ -18,15 +18,6 @@ use Drupal\Core\TypedData\DataDefinition; */ abstract class TextItemBase extends FieldItemBase { - /** - * {@inheritdoc} - */ - public static function defaultInstanceSettings() { - $settings = parent::defaultInstanceSettings(); - $settings['text_processing'] = 0; - return $settings; - } - /** * {@inheritdoc} */ diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php index 1c74a41e1079..bf1054f7ad8a 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextLongItem.php @@ -8,15 +8,14 @@ namespace Drupal\text\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\Form\FormStateInterface; /** * Plugin implementation of the 'text_long' field type. * * @FieldType( * id = "text_long", - * label = @Translation("Long text"), - * description = @Translation("This field stores long text in the database."), + * label = @Translation("Text (formatted, long)"), + * description = @Translation("This field stores a long text with a text format."), * default_widget = "text_textarea", * default_formatter = "text_default" * ) @@ -46,23 +45,4 @@ class TextLongItem extends TextItemBase { ); } - /** - * {@inheritdoc} - */ - public function instanceSettingsForm(array $form, FormStateInterface $form_state) { - $element = array(); - - $element['text_processing'] = array( - '#type' => 'radios', - '#title' => t('Text processing'), - '#default_value' => $this->getSetting('text_processing'), - '#options' => array( - t('Plain text'), - t('Filtered text (user selects text format)'), - ), - ); - - return $element; - } - } diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php index 7ffcd64d0f7e..fd8b5281e26e 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php @@ -16,8 +16,8 @@ use Drupal\Core\TypedData\DataDefinition; * * @FieldType( * id = "text_with_summary", - * label = @Translation("Long text and summary"), - * description = @Translation("This field stores long text in the database along with optional summary text."), + * label = @Translation("Text (formatted, long, with summary)"), + * description = @Translation("This field stores long text with a format and an optional summary."), * default_widget = "text_textarea_with_summary", * default_formatter = "text_default" * ) @@ -29,7 +29,6 @@ class TextWithSummaryItem extends TextItemBase { */ public static function defaultInstanceSettings() { return array( - 'text_processing' => 1, 'display_summary' => 0, ) + parent::defaultInstanceSettings(); } @@ -96,15 +95,6 @@ class TextWithSummaryItem extends TextItemBase { $element = array(); $settings = $this->getSettings(); - $element['text_processing'] = array( - '#type' => 'radios', - '#title' => t('Text processing'), - '#default_value' => $settings['text_processing'], - '#options' => array( - t('Plain text'), - t('Filtered text (user selects text format)'), - ), - ); $element['display_summary'] = array( '#type' => 'checkbox', '#title' => t('Summary input'), diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php index ef6a5db7609a..0ac31511b99a 100644 --- a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php +++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWidget.php @@ -31,15 +31,11 @@ class TextareaWidget extends StringTextareaWidget { public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $main_widget = parent::formElement($items, $delta, $element, $form, $form_state); - if ($this->getFieldSetting('text_processing')) { - $element = $main_widget['value']; - $element['#type'] = 'text_format'; - $element['#format'] = $items[$delta]->format; - $element['#base_type'] = $main_widget['value']['#type']; - return $element; - } - - return $main_widget; + $element = $main_widget['value']; + $element['#type'] = 'text_format'; + $element['#format'] = $items[$delta]->format; + $element['#base_type'] = $main_widget['value']['#type']; + return $element; } /** diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php index c9b5dcd0a17b..ab2f19a9cfd4 100644 --- a/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php +++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextfieldWidget.php @@ -8,7 +8,7 @@ namespace Drupal\text\Plugin\Field\FieldWidget; use Drupal\Core\Field\FieldItemListInterface; -use Drupal\Core\Field\Plugin\Field\FieldWidget\StringWidget; +use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\Validator\ConstraintViolationInterface; @@ -19,12 +19,11 @@ use Symfony\Component\Validator\ConstraintViolationInterface; * id = "text_textfield", * label = @Translation("Text field"), * field_types = { - * "text", - * "string" + * "text" * }, * ) */ -class TextfieldWidget extends StringWidget { +class TextfieldWidget extends StringTextfieldWidget { /** * {@inheritdoc} @@ -32,14 +31,11 @@ class TextfieldWidget extends StringWidget { public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $main_widget = parent::formElement($items, $delta, $element, $form, $form_state); - if ($this->getFieldSetting('text_processing')) { - $element = $main_widget['value']; - $element['#type'] = 'text_format'; - $element['#format'] = isset($items[$delta]->format) ? $items[$delta]->format : NULL; - $element['#base_type'] = $main_widget['value']['#type']; - return $element; - } - return $main_widget; + $element = $main_widget['value']; + $element['#type'] = 'text_format'; + $element['#format'] = isset($items[$delta]->format) ? $items[$delta]->format : NULL; + $element['#base_type'] = $main_widget['value']['#type']; + return $element; } /** diff --git a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php index b789677f291f..c9e042243215 100644 --- a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php +++ b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php @@ -54,9 +54,8 @@ class TextFormatterTest extends EntityUnitTestBase { ), ))->save(); - // Set up two fields: one with text processing enabled, the other disabled. entity_create('field_storage_config', array( - 'name' => 'processed_text', + 'name' => 'formatted_text', 'entity_type' => $this->entityType, 'type' => 'text', 'settings' => array(), @@ -64,26 +63,8 @@ class TextFormatterTest extends EntityUnitTestBase { entity_create('field_instance_config', array( 'entity_type' => $this->entityType, 'bundle' => $this->bundle, - 'field_name' => 'processed_text', - 'label' => 'Processed text', - 'settings' => array( - 'text_processing' => TRUE, - ), - ))->save(); - entity_create('field_storage_config', array( - 'name' => 'unprocessed_text', - 'entity_type' => $this->entityType, - 'type' => 'text', - 'settings' => array(), - ))->save(); - entity_create('field_instance_config', array( - 'entity_type' => $this->entityType, - 'bundle' => $this->bundle, - 'field_name' => 'unprocessed_text', - 'label' => 'Unprocessed text', - 'settings' => array( - 'text_processing' => FALSE, - ), + 'field_name' => 'formatted_text', + 'label' => 'Filtered text', ))->save(); } @@ -99,29 +80,21 @@ class TextFormatterTest extends EntityUnitTestBase { // Create the entity to be referenced. $entity = entity_create($this->entityType, array('name' => $this->randomMachineName())); - $entity->processed_text = array( + $entity->formatted_text = array( 'value' => 'Hello, world!', 'format' => 'my_text_format', ); - $entity->unprocessed_text = array( - 'value' => 'Hello, world!', - ); $entity->save(); foreach ($formatters as $formatter) { - // Verify the processed text field formatter's render array. - $build = $entity->get('processed_text')->view(array('type' => $formatter)); + // Verify the text field formatter's render array. + $build = $entity->get('formatted_text')->view(array('type' => $formatter)); drupal_render($build[0]); $this->assertEqual($build[0]['#markup'], "
Hello, world!
\n"); $expected_cache_tags = array( 'filter_format' => array('my_text_format'), ); - $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags when formatting a processed text field.', array('@formatter' => $formatter))); - - // Verify the unprocessed text field formatter's render array. - $build = $entity->get('unprocessed_text')->view(array('type' => $formatter)); - $this->assertEqual($build[0]['#markup'], 'Hello, world!'); - $this->assertTrue(!isset($build[0]['#cache']), format_string('The @formatter formatter has the expected cache tags when formatting an unprocessed text field.', array('@formatter' => $formatter))); + $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter))); } } diff --git a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php deleted file mode 100644 index f6f915053a3b..000000000000 --- a/core/modules/text/src/Tests/Formatter/TextPlainUnitTest.php +++ /dev/null @@ -1,362 +0,0 @@ -installConfig(array('system', 'field')); - $this->installEntitySchema('entity_test'); - - // @todo Add helper methods for all of the following. - - $this->entity_type = 'entity_test'; - if (!isset($this->bundle)) { - $this->bundle = $this->entity_type; - } - - $this->field_name = drupal_strtolower($this->randomMachineName()); - $this->field_type = 'text_long'; - $this->field_settings = array(); - $this->instance_settings = array( - 'text_processing' => FALSE, - ); - - $this->formatter_type = 'string'; - $this->formatter_settings = array(); - - $this->fieldStorage = entity_create('field_storage_config', array( - 'name' => $this->field_name, - 'entity_type' => $this->entity_type, - 'type' => $this->field_type, - 'settings' => $this->field_settings, - )); - $this->fieldStorage->save(); - - $this->instance = entity_create('field_instance_config', array( - 'field_storage' => $this->fieldStorage, - 'bundle' => $this->bundle, - 'label' => $this->randomMachineName(), - 'settings' => $this->instance_settings, - )); - $this->instance->save(); - - $this->view_mode = 'default'; - $this->display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode) - ->setComponent($this->field_name, array( - 'type' => $this->formatter_type, - 'settings' => $this->formatter_settings, - )); - $this->display->save(); - - $this->langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED; - } - - /** - * Creates an entity of type $this->entity_type and bundle $this->bundle. - * - * @param array $values - * (optional) Additional values to pass to entity_create(). - * - * @return \Drupal\Core\Entity\EntityInterface - * The created entity object. - */ - protected function createEntity($values = array()) { - $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type); - $bundle_key = $entity_type->getKey('bundle'); - $entity = entity_create($this->entity_type, $values + array( - $bundle_key => $this->bundle, - )); - return $entity; - } - - /** - * Renders fields of a given entity with a given display. - * - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * The entity object with attached fields to render. - * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display - * The display to render the fields in. - */ - protected function renderEntityFields(ContentEntityInterface $entity, EntityViewDisplayInterface $display) { - $content = $display->build($entity); - $content = $this->render($content); - return $content; - } - - /** - * Formats an assertion message string. - * - * Unlike format_string(), - * - all replacement tokens are exported via var_export() and sanitized for - * output, regardless of token type used (i.e., '@', '!', and '%' do not - * have any special meaning). - * - Replacement token values containing newlines are automatically wrapped - * into a PRE element to aid in debugging test failures. - * - * @param string $message - * The assertion message string containing placeholders. - * @param array $args - * An array of replacement token values to inject into $message. - * - * @return string - * The $message with exported replacement tokens, sanitized for HTML output. - * - * @see \Drupal\Component\Utility\String::checkPlain() - * @see format_string() - */ - protected function formatString($message, array $args) { - array_walk($args, function (&$value) { - // Export/dump the raw replacement token value. - $value = var_export($value, TRUE); - // Sanitize the value for output. - $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); - // Wrap the value in a PRE element if it contains newlines. - if (strpos($value, "\n")) { - $value = '' . $value . ''; - } - }); - return strtr($message, $args); - } - - /** - * Gets the plain-text version of $this->content. - * - * @param string $content - * A (HTML) string. - * - * @return string - * The $content with all HTML tags stripped and all HTML entities replaced - * with their actual characters. - */ - protected function getPlainTextContent($content) { - // Strip all HTML tags. - $content = strip_tags($content); - // Decode all HTML entities (e.g., ' ') into characters. - $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8'); - return $content; - } - - /** - * Asserts that a raw string appears in $this->content. - * - * @param string $value - * The raw string to look for. - * @param string $message - * (optional) An assertion message. If omitted, a default message is used. - * Available placeholders: - * - @value: The $value. - * - @content: The current value of $this->content. - * @param array $args - * (optional) Additional replacement token map to pass to formatString(). - * - * @return bool - * TRUE on pass, FALSE on fail. - */ - protected function assertRaw($value, $message = NULL, $args = array()) { - if (!isset($message)) { - $message = 'Raw string @value found in @content'; - } - $args += array( - '@value' => $value, - '@content' => $this->content, - ); - return $this->assert(strpos($this->content, $value) !== FALSE, $this->formatString($message, $args)); - } - - /** - * Asserts that a raw string does not appear in $this->content. - * - * @param string $value - * The raw string to look for. - * @param string $message - * (optional) An assertion message. If omitted, a default message is used. - * Available placeholders: - * - @value: The $value. - * - @content: The current value of $this->content. - * @param array $args - * (optional) Additional replacement token map to pass to formatString(). - * - * @return bool - * TRUE on pass, FALSE on fail. - */ - protected function assertNoRaw($value, $message = NULL, $args = array()) { - if (!isset($message)) { - $message = 'Raw string @value not found in @content'; - } - $args += array( - '@value' => $value, - '@content' => $this->content, - ); - return $this->assert(strpos($this->content, $value) === FALSE, $this->formatString($message, $args)); - } - - /** - * Asserts that a text string appears in the text-only version of $this->content. - * - * @param string $value - * The text string to look for. - * @param string $message - * (optional) An assertion message. If omitted, a default message is used. - * Available placeholders: - * - @value: The $value. - * - @content: The current value of $this->content. - * @param array $args - * (optional) Additional replacement token map to pass to formatString(). - * - * @return bool - * TRUE on pass, FALSE on fail. - */ - protected function assertText($value, $message = NULL, $args = array()) { - if (!isset($message)) { - $message = 'Text string @value found in @content'; - } - $content = $this->getPlainTextContent($this->content); - $args += array( - '@value' => $value, - '@content' => $content, - ); - return $this->assert(strpos($content, $value) !== FALSE, $this->formatString($message, $args)); - } - - /** - * Asserts that a text string does not appear in the text-only version of $this->content. - * - * @param string $value - * The text string to look for. - * @param string $message - * (optional) An assertion message. If omitted, a default message is used. - * Available placeholders: - * - @value: The $value. - * - @content: The current value of $this->content. - * @param array $args - * (optional) Additional replacement token map to pass to formatString(). - * - * @return bool - * TRUE on pass, FALSE on fail. - */ - protected function assertNoText($value, $message = NULL, $args = array()) { - if (!isset($message)) { - $message = 'Text string @value not found in @content'; - } - $content = $this->getPlainTextContent($this->content); - $args += array( - '@value' => $value, - '@content' => $content, - ); - return $this->assert(strpos($content, $value) === FALSE, $this->formatString($message, $args)); - } - - /** - * Tests text_plain formatter output. - */ - function testPlainText() { - $value = $this->randomString(); - $value .= "\n\n" . $this->randomString() . ''; - $value .= "\n\n" . $this->randomString(); - - $entity = $this->createEntity(array()); - $entity->{$this->field_name}->value = $value; - - // Verify that all HTML is escaped and newlines are retained. - $this->renderEntityFields($entity, $this->display); - $this->assertText($value); - $this->assertNoRaw($value); - $this->assertRaw(nl2br(String::checkPlain($value))); - } - -} diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php index 330d9f854151..9f825246de0c 100644 --- a/core/modules/text/src/Tests/TextFieldTest.php +++ b/core/modules/text/src/Tests/TextFieldTest.php @@ -96,9 +96,6 @@ class TextFieldTest extends WebTestBase { 'field_storage' => $field_storage, 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label', - 'settings' => array( - 'text_processing' => TRUE, - ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( @@ -162,9 +159,6 @@ class TextFieldTest extends WebTestBase { 'field_storage' => $field_storage, 'bundle' => 'entity_test', 'label' => $this->randomMachineName() . '_label', - 'settings' => array( - 'text_processing' => TRUE, - ), ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($field_name, array( diff --git a/core/modules/text/src/Tests/TextWithSummaryItemTest.php b/core/modules/text/src/Tests/TextWithSummaryItemTest.php index 04f813a52962..bbb88d80cd7c 100644 --- a/core/modules/text/src/Tests/TextWithSummaryItemTest.php +++ b/core/modules/text/src/Tests/TextWithSummaryItemTest.php @@ -72,18 +72,8 @@ class TextWithSummaryItemTest extends FieldUnitTestBase { $this->assertTrue($entity->summary_field instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertTrue($entity->summary_field[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertEqual($entity->summary_field->value, $value); - $this->assertEqual($entity->summary_field->processed, $value); $this->assertEqual($entity->summary_field->summary, $summary); - $this->assertEqual($entity->summary_field->summary_processed, $summary); $this->assertNull($entity->summary_field->format); - - // Enable text processing. - $this->instance->settings['text_processing'] = 1; - $this->instance->save(); - - // Re-load the entity. - $entity = entity_load($entity_type, $entity->id(), TRUE); - // Even if no format is given, if text processing is enabled, the default // format is used. $this->assertEqual($entity->summary_field->processed, "
$value
\n"); @@ -120,9 +110,6 @@ class TextWithSummaryItemTest extends FieldUnitTestBase { $this->instance = entity_create('field_instance_config', array( 'field_storage' => $this->fieldStorage, 'bundle' => $entity_type, - 'settings' => array( - 'text_processing' => 0, - ) )); $this->instance->save(); } diff --git a/core/modules/text/src/TextProcessed.php b/core/modules/text/src/TextProcessed.php index 321962b4ee1a..d06ce01869b9 100644 --- a/core/modules/text/src/TextProcessed.php +++ b/core/modules/text/src/TextProcessed.php @@ -55,13 +55,8 @@ class TextProcessed extends TypedData { if (!isset($text) || $text === '') { $this->processed = ''; } - elseif ($item->getFieldDefinition()->getSetting('text_processing')) { - $this->processed = check_markup($text, $item->format, $item->getLangcode()); - } else { - // Escape all HTML and retain newlines. - // @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\StringFormatter - $this->processed = SafeMarkup::set(nl2br(String::checkPlain($text))); + $this->processed = check_markup($text, $item->format, $item->getLangcode()); } return $this->processed; } diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 161248726f64..96dcd8fbed83 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -157,12 +157,3 @@ function text_summary($text, $format = NULL, $size = NULL) { return $summary; } - -/** - * Implements hook_field_formatter_info_alter(). - */ -function text_field_formatter_info_alter(&$info) { - $info['string']['field_types'][] = 'text'; - $info['string']['field_types'][] = 'text_with_summary'; - $info['string']['field_types'][] = 'text_long'; -} diff --git a/core/profiles/standard/config/install/core.entity_form_display.node.article.default.yml b/core/profiles/standard/config/install/core.entity_form_display.node.article.default.yml index 359aa183a9c8..bdf54f02c5ac 100644 --- a/core/profiles/standard/config/install/core.entity_form_display.node.article.default.yml +++ b/core/profiles/standard/config/install/core.entity_form_display.node.article.default.yml @@ -4,7 +4,7 @@ bundle: article mode: default content: title: - type: string + type: string_textfield weight: 0 settings: size: 60