Issue #2313757 by Berdir, Wim Leers, dawehner: Remove text_processing option from text fields, expose existing string field types as plain text in UI.

8.0.x
Alex Pott 2014-09-17 21:59:08 +01:00
parent 55ef0e86e0
commit 57926bf527
65 changed files with 375 additions and 801 deletions

View File

@ -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:

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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}

View File

@ -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,
));

View File

@ -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);

View File

@ -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();

View File

@ -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,
))

View File

@ -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'));
}
}

View File

@ -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 {

View File

@ -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);

View File

@ -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();

View File

@ -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);
}));
}

View File

@ -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

View File

@ -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 {

View File

@ -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.

View File

@ -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) {

View File

@ -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.
*/

View File

@ -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(

View File

@ -0,0 +1,127 @@
<?php
/**
* @file
* Contains \Drupal\field\Tests\String\StringFormatterTest.
*/
namespace Drupal\field\Tests\String;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the creation of text fields.
*
* @group field
*/
class StringFormatterTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('entity', 'field', 'text', 'entity_test', 'system', 'filter', 'user');
/**
* @var string
*/
protected $entityType;
/**
* @var string
*/
protected $bundle;
/**
* @var string
*/
protected $fieldName;
/**
* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
*/
protected $display;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Configure the theme system.
$this->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<strong>" . $this->randomString() . '</strong>';
$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.'));
}
}

View File

@ -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();
}

View File

@ -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'));

View File

@ -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);
}
}

View File

@ -8,8 +8,7 @@ description: ''
required: false
default_value: { }
default_value_function: ''
settings:
text_processing: 0
settings: { }
field_type: text
dependencies:
entity:

View File

@ -8,8 +8,7 @@ description: ''
required: false
default_value: { }
default_value_function: ''
settings:
text_processing: 0
settings: { }
field_type: text
dependencies:
entity:

View File

@ -8,8 +8,7 @@ description: ''
required: false
default_value: { }
default_value_function: ''
settings:
text_processing: 0
settings: { }
field_type: text
dependencies:
entity:

View File

@ -9,8 +9,7 @@ description: ''
required: '0'
default_value: { }
default_value_function: ''
settings:
text_processing: '0'
settings: { }
field_type: text
dependencies:
entity:

View File

@ -9,8 +9,7 @@ description: ''
required: '0'
default_value: { }
default_value_function: ''
settings:
text_processing: '0'
settings: { }
field_type: text
dependencies:
entity:

View File

@ -9,8 +9,7 @@ description: ''
required: '0'
default_value: { }
default_value_function: ''
settings:
text_processing: '0'
settings: { }
field_type: text
dependencies:
entity:

View File

@ -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:

View File

@ -5,7 +5,7 @@ mode: default
status: true
content:
name:
type: string
type: string_textfield
weight: -5
settings:
size: 60

View File

@ -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,
));

View File

@ -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'];

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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(

View File

@ -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 {

View File

@ -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.");

View File

@ -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),

View File

@ -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;
}

View File

@ -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(

View File

@ -0,0 +1,59 @@
<?php
/**
* @file
* Contains \Drupal\rdf\Tests\Field\TextFieldRdfaTest.
*/
namespace Drupal\rdf\Tests\Field;
/**
* Tests RDFa output by text field formatters.
*
* @group rdf
*/
class StringFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
protected $fieldType = 'string';
/**
* The 'value' property value for testing.
*
* @var string
*/
protected $testValue = 'test_text_value';
/**
* The 'summary' property value for testing.
*
* @var string
*/
protected $testSummary = 'test_summary_value';
public function setUp() {
parent::setUp();
$this->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));
}
}

View File

@ -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));
}
}

View File

@ -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,

View File

@ -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');

View File

@ -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 <strong>text</strong> text to filter.";
$entity->field_test_text->format = filter_default_format();

View File

@ -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.');
}

View File

@ -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',

View File

@ -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

View File

@ -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;
}
}

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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}
*/

View File

@ -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;
}
}

View File

@ -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'),

View File

@ -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;
}
/**

View File

@ -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;
}
/**

View File

@ -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'], "<p>Hello, world!</p>\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)));
}
}

View File

@ -1,362 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\text\Tests\Formatter\TextPlainUnitTest.
*/
namespace Drupal\text\Tests\Formatter;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Tests the creation of text fields.
*
* @group text
* @todo Move assertion helper methods into KernelTestBase.
* @todo Move field helper methods, $modules, and setUp() into a new
* FieldPluginUnitTestBase.
*/
class TextPlainUnitTest extends DrupalUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('entity', 'field', 'text', 'entity_test', 'system', 'filter', 'user');
/**
* @var string
*/
protected $entity_type;
/**
* @var string
*/
protected $bundle;
/**
* @var string
*/
protected $field_name;
/**
* @var string
*/
protected $field_type;
/**
* @var array
*/
protected $field_settings;
/**
* @var array
*/
protected $instance_settings;
/**
* @var string
*/
protected $formatter_type;
/**
* @var array
*/
protected $formatter_settings;
/**
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $fieldStorage;
/**
* @var \Drupal\field\Entity\FieldInstanceConfig
*/
protected $instance;
/**
* @var string
*/
protected $view_mode;
/**
* @var \Drupal\entity\Entity\EntityViewDisplay
*/
protected $display;
/**
* @var string
*/
protected $langcode;
protected function setUp() {
parent::setUp();
// Configure the theme system.
$this->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 = '<pre style="white-space: pre-wrap;">' . $value . '</pre>';
}
});
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., '&nbsp;') 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<strong>" . $this->randomString() . '</strong>';
$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)));
}
}

View File

@ -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(

View File

@ -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, "<p>$value</p>\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();
}

View File

@ -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;
}

View File

@ -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';
}

View File

@ -4,7 +4,7 @@ bundle: article
mode: default
content:
title:
type: string
type: string_textfield
weight: 0
settings:
size: 60