Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -3,10 +3,12 @@ label: Drupal teaser length configuration
|
|||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
- teaser_length
|
||||
source_module: text
|
||||
process:
|
||||
default_summary_length: teaser_length
|
||||
destination:
|
|
@ -16,4 +16,4 @@ namespace Drupal\text\Plugin\Field\FieldFormatter;
|
|||
* }
|
||||
* )
|
||||
*/
|
||||
class TextSummaryOrTrimmedFormatter extends TextTrimmedFormatter { }
|
||||
class TextSummaryOrTrimmedFormatter extends TextTrimmedFormatter {}
|
||||
|
|
|
@ -62,7 +62,7 @@ class TextItem extends TextItemBase {
|
|||
'Length' => [
|
||||
'max' => $max_length,
|
||||
'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]),
|
||||
]
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@ abstract class TextItemBase extends FieldItemBase {
|
|||
->setDescription(t('The text with the text format applied.'))
|
||||
->setComputed(TRUE)
|
||||
->setClass('\Drupal\text\TextProcessed')
|
||||
->setSetting('text source', 'value');
|
||||
->setSetting('text source', 'value')
|
||||
->setInternal(FALSE);
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
|
|
@ -87,15 +87,7 @@ class TextareaWithSummaryWidget extends TextareaWidget {
|
|||
*/
|
||||
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
|
||||
$element = parent::errorElement($element, $violation, $form, $form_state);
|
||||
if ($element === FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
elseif (isset($violation->arrayPropertyPath[0])) {
|
||||
return $element[$violation->arrayPropertyPath[0]];
|
||||
}
|
||||
else {
|
||||
return $element;
|
||||
}
|
||||
return ($element === FALSE) ? FALSE : $element[$violation->arrayPropertyPath[0]];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\text\Plugin\migrate\cckfield;
|
||||
|
||||
@trigger_error('TextField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\text\Plugin\migrate\field\d6\TextField or \Drupal\text\Plugin\migrate\field\d7\TextField instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
@ -14,8 +16,16 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
|||
* "text_long" = "text_long",
|
||||
* "text_with_summary" = "text_with_summary"
|
||||
* },
|
||||
* core = {6,7}
|
||||
* core = {6,7},
|
||||
* source_module = "text",
|
||||
* destination_module = "text",
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
|
||||
* \Drupal\text\Plugin\migrate\field\d6\TextField or
|
||||
* \Drupal\text\Plugin\migrate\field\d7\TextField instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/2751897
|
||||
*/
|
||||
class TextField extends CckFieldPluginBase {
|
||||
|
||||
|
@ -43,7 +53,9 @@ class TextField extends CckFieldPluginBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $field_info) {
|
||||
if ($field_info['widget_type'] == 'optionwidgets_onoff') {
|
||||
$widget_type = isset($field_info['widget_type']) ? $field_info['widget_type'] : $field_info['widget']['type'];
|
||||
|
||||
if ($widget_type == 'optionwidgets_onoff') {
|
||||
$process = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
|
@ -88,7 +100,7 @@ class TextField extends CckFieldPluginBase {
|
|||
}
|
||||
|
||||
$process = [
|
||||
'plugin' => 'iterator',
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => $process,
|
||||
];
|
||||
|
|
133
web/core/modules/text/src/Plugin/migrate/field/d6/TextField.php
Normal file
133
web/core/modules/text/src/Plugin/migrate/field/d6/TextField.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\text\Plugin\migrate\field\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "d6_text",
|
||||
* type_map = {
|
||||
* "text" = "text",
|
||||
* "text_long" = "text_long",
|
||||
* "text_with_summary" = "text_with_summary"
|
||||
* },
|
||||
* core = {6},
|
||||
* source_module = "text",
|
||||
* destination_module = "text",
|
||||
* )
|
||||
*/
|
||||
class TextField extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldWidgetMap() {
|
||||
return [
|
||||
'text_textfield' => 'text_textfield',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [
|
||||
'default' => 'text_default',
|
||||
'trimmed' => 'text_trimmed',
|
||||
'plain' => 'basic_string',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $field_info) {
|
||||
$widget_type = isset($field_info['widget_type']) ? $field_info['widget_type'] : $field_info['widget']['type'];
|
||||
|
||||
if ($widget_type == 'optionwidgets_onoff') {
|
||||
$process = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
],
|
||||
];
|
||||
|
||||
$checked_value = explode("\n", $field_info['global_settings']['allowed_values'])[1];
|
||||
if (strpos($checked_value, '|') !== FALSE) {
|
||||
$checked_value = substr($checked_value, 0, strpos($checked_value, '|'));
|
||||
}
|
||||
$process['value']['map'][$checked_value] = 1;
|
||||
}
|
||||
else {
|
||||
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
|
||||
// signature_format for an example of the YAML that represents this
|
||||
// process array.
|
||||
$process = [
|
||||
'value' => 'value',
|
||||
'format' => [
|
||||
[
|
||||
'plugin' => 'static_map',
|
||||
'bypass' => TRUE,
|
||||
'source' => 'format',
|
||||
'map' => [0 => NULL],
|
||||
],
|
||||
[
|
||||
'plugin' => 'skip_on_empty',
|
||||
'method' => 'process',
|
||||
],
|
||||
[
|
||||
'plugin' => 'migration',
|
||||
'migration' => [
|
||||
'd6_filter_format',
|
||||
'd7_filter_format',
|
||||
],
|
||||
'source' => 'format',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$process = [
|
||||
'plugin' => 'sub_process',
|
||||
'source' => $field_name,
|
||||
'process' => $process,
|
||||
];
|
||||
$migration->setProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldType(Row $row) {
|
||||
$widget_type = $row->getSourceProperty('widget_type');
|
||||
$settings = $row->getSourceProperty('global_settings');
|
||||
|
||||
if ($widget_type == 'text_textfield') {
|
||||
$field_type = $settings['text_processing'] ? 'text' : 'string';
|
||||
if (empty($settings['max_length']) || $settings['max_length'] > 255) {
|
||||
$field_type .= '_long';
|
||||
}
|
||||
return $field_type;
|
||||
}
|
||||
|
||||
if ($widget_type == 'text_textarea') {
|
||||
$field_type = $settings['text_processing'] ? 'text_long' : 'string_long';
|
||||
return $field_type;
|
||||
}
|
||||
|
||||
switch ($widget_type) {
|
||||
case 'optionwidgets_buttons':
|
||||
case 'optionwidgets_select':
|
||||
return 'list_string';
|
||||
case 'optionwidgets_onoff':
|
||||
return 'boolean';
|
||||
default:
|
||||
return parent::getFieldType($row);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
107
web/core/modules/text/src/Plugin/migrate/field/d7/TextField.php
Normal file
107
web/core/modules/text/src/Plugin/migrate/field/d7/TextField.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\text\Plugin\migrate\field\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate\MigrateSkipRowException;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
|
||||
/**
|
||||
* @MigrateField(
|
||||
* id = "d7_text",
|
||||
* type_map = {
|
||||
* "text" = "text",
|
||||
* "text_long" = "text_long",
|
||||
* "text_with_summary" = "text_with_summary"
|
||||
* },
|
||||
* core = {7},
|
||||
* source_module = "text",
|
||||
* destination_module = "text",
|
||||
* )
|
||||
*/
|
||||
class TextField extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterType(Row $row) {
|
||||
$field_type = $this->getFieldType($row);
|
||||
$formatter_type = $row->getSourceProperty('formatter/type');
|
||||
|
||||
switch ($field_type) {
|
||||
case 'string':
|
||||
$formatter_type = str_replace('text_default', 'string', $formatter_type);
|
||||
break;
|
||||
case 'string_long':
|
||||
$formatter_type = str_replace('text_default', 'basic_string', $formatter_type);
|
||||
break;
|
||||
}
|
||||
|
||||
return $formatter_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldWidgetType(Row $row) {
|
||||
$field_type = $this->getFieldType($row);
|
||||
$widget_type = $row->getSourceProperty('widget/type');
|
||||
|
||||
switch ($field_type) {
|
||||
case 'string':
|
||||
$widget_type = str_replace('text_textfield', 'string_textfield', $widget_type);
|
||||
break;
|
||||
case 'string_long':
|
||||
$widget_type = str_replace('text_textarea', 'string_textarea', $widget_type);
|
||||
break;
|
||||
}
|
||||
|
||||
return $widget_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldType(Row $row) {
|
||||
$type = $row->getSourceProperty('type');
|
||||
$plain_text = FALSE;
|
||||
$filtered_text = FALSE;
|
||||
|
||||
foreach ($row->getSourceProperty('instances') as $instance) {
|
||||
// Check if this field has plain text instances, filtered text instances,
|
||||
// or both.
|
||||
$data = unserialize($instance['data']);
|
||||
switch ($data['settings']['text_processing']) {
|
||||
case '0':
|
||||
$plain_text = TRUE;
|
||||
break;
|
||||
case '1':
|
||||
$filtered_text = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($type, ['text', 'text_long'])) {
|
||||
// If a text or text_long field has only plain text instances, migrate it
|
||||
// to a string or string_long field.
|
||||
if ($plain_text && !$filtered_text) {
|
||||
$type = str_replace(['text', 'text_long'], ['string', 'string_long'], $type);
|
||||
}
|
||||
// If a text or text_long field has both plain text and filtered text
|
||||
// instances, skip the row.
|
||||
elseif ($plain_text && $filtered_text) {
|
||||
$field_name = $row->getSourceProperty('field_name');
|
||||
throw new MigrateSkipRowException("Can't migrate source field $field_name configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
|
||||
}
|
||||
}
|
||||
elseif ($type == 'text_with_summary' && $plain_text) {
|
||||
// If a text_with_summary field has plain text instances, skip the row
|
||||
// since there's no such thing as a string_with_summary field.
|
||||
$field_name = $row->getSourceProperty('field_name');
|
||||
throw new MigrateSkipRowException("Can't migrate source field $field_name of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
namespace Drupal\text;
|
||||
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\Core\TypedData\TypedDataInterface;
|
||||
use Drupal\Core\TypedData\TypedData;
|
||||
use Drupal\filter\FilterProcessResult;
|
||||
use Drupal\filter\Render\FilteredMarkup;
|
||||
|
||||
/**
|
||||
* A computed property for processing text with a format.
|
||||
|
@ -12,12 +15,12 @@ use Drupal\Core\TypedData\TypedData;
|
|||
* Required settings (below the definition's 'settings' key) are:
|
||||
* - text source: The text property containing the to be processed text.
|
||||
*/
|
||||
class TextProcessed extends TypedData {
|
||||
class TextProcessed extends TypedData implements CacheableDependencyInterface {
|
||||
|
||||
/**
|
||||
* Cached processed text.
|
||||
*
|
||||
* @var string|null
|
||||
* @var \Drupal\filter\FilterProcessResult|null
|
||||
*/
|
||||
protected $processed = NULL;
|
||||
|
||||
|
@ -37,20 +40,29 @@ class TextProcessed extends TypedData {
|
|||
*/
|
||||
public function getValue() {
|
||||
if ($this->processed !== NULL) {
|
||||
return $this->processed;
|
||||
return FilteredMarkup::create($this->processed->getProcessedText());
|
||||
}
|
||||
|
||||
$item = $this->getParent();
|
||||
$text = $item->{($this->definition->getSetting('text source'))};
|
||||
|
||||
// Avoid running check_markup() on empty strings.
|
||||
// Avoid doing unnecessary work on empty strings.
|
||||
if (!isset($text) || $text === '') {
|
||||
$this->processed = '';
|
||||
$this->processed = new FilterProcessResult('');
|
||||
}
|
||||
else {
|
||||
$this->processed = check_markup($text, $item->format, $item->getLangcode());
|
||||
$build = [
|
||||
'#type' => 'processed_text',
|
||||
'#text' => $text,
|
||||
'#format' => $item->format,
|
||||
'#filter_types_to_skip' => [],
|
||||
'#langcode' => $item->getLangcode(),
|
||||
];
|
||||
// Capture the cacheability metadata associated with the processed text.
|
||||
$processed_text = $this->getRenderer()->renderPlain($build);
|
||||
$this->processed = FilterProcessResult::createFromRenderArray($build)->setProcessedText((string) $processed_text);
|
||||
}
|
||||
return $this->processed;
|
||||
return FilteredMarkup::create($this->processed->getProcessedText());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,4 +76,37 @@ class TextProcessed extends TypedData {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheTags() {
|
||||
$this->getValue();
|
||||
return $this->processed->getCacheTags();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheContexts() {
|
||||
$this->getValue();
|
||||
return $this->processed->getCacheContexts();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheMaxAge() {
|
||||
$this->getValue();
|
||||
return $this->processed->getCacheMaxAge();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the renderer service.
|
||||
*
|
||||
* @return \Drupal\Core\Render\RendererInterface
|
||||
*/
|
||||
protected function getRenderer() {
|
||||
return \Drupal::service('renderer');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\text\Tests;
|
||||
namespace Drupal\Tests\text\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Tests\String\StringFieldTest;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
use Drupal\Tests\field\Functional\String\StringFieldTest;
|
||||
use Drupal\Tests\TestFileCreationTrait;
|
||||
|
||||
/**
|
||||
* Tests the creation of text fields.
|
||||
|
@ -16,6 +17,10 @@ use Drupal\filter\Entity\FilterFormat;
|
|||
*/
|
||||
class TextFieldTest extends StringFieldTest {
|
||||
|
||||
use TestFileCreationTrait {
|
||||
getTestFiles as drupalGetTestFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* A user with relevant administrative privileges.
|
||||
*
|
||||
|
@ -37,14 +42,14 @@ class TextFieldTest extends StringFieldTest {
|
|||
public function testTextFieldValidation() {
|
||||
// Create a field with settings to validate.
|
||||
$max_length = 3;
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'text',
|
||||
'settings' => [
|
||||
'max_length' => $max_length,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
|
@ -90,7 +95,7 @@ class TextFieldTest extends StringFieldTest {
|
|||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $file_field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'file'
|
||||
'type' => 'file',
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
|
@ -113,11 +118,11 @@ class TextFieldTest extends StringFieldTest {
|
|||
->save();
|
||||
|
||||
$test_file = current($this->drupalGetTestFiles('text'));
|
||||
$edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
|
||||
$edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri);
|
||||
$this->drupalPostForm('entity_test/add', $edit, 'Upload');
|
||||
$this->assertResponse(200);
|
||||
$edit = [
|
||||
'text_long[0][value]' => 'Long text'
|
||||
'text_long[0][value]' => 'Long text',
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, 'Save');
|
||||
$this->assertResponse(200);
|
||||
|
@ -149,11 +154,11 @@ class TextFieldTest extends StringFieldTest {
|
|||
$renderer = $this->container->get('renderer');
|
||||
|
||||
// Create a field.
|
||||
$field_name = Unicode::strtolower($this->randomMachineName());
|
||||
$field_name = mb_strtolower($this->randomMachineName());
|
||||
$field_storage = FieldStorageConfig::create([
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => $field_type
|
||||
'type' => $field_type,
|
||||
]);
|
||||
$field_storage->save();
|
||||
FieldConfig::create([
|
||||
|
@ -191,7 +196,7 @@ class TextFieldTest extends StringFieldTest {
|
|||
"{$field_name}[0][value]" => $value,
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
|
||||
preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match);
|
||||
$id = $match[1];
|
||||
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
|
||||
|
||||
|
@ -199,15 +204,15 @@ class TextFieldTest extends StringFieldTest {
|
|||
$entity = EntityTest::load($id);
|
||||
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
|
||||
$content = $display->build($entity);
|
||||
$this->setRawContent($renderer->renderRoot($content));
|
||||
$this->assertNoRaw($value, 'HTML tags are not displayed.');
|
||||
$this->assertEscaped($value, 'Escaped HTML is displayed correctly.');
|
||||
$rendered_entity = \Drupal::service('renderer')->renderRoot($content);
|
||||
$this->assertNotContains($value, (string) $rendered_entity);
|
||||
$this->assertContains(Html::escape($value), (string) $rendered_entity);
|
||||
|
||||
// Create a new text format that does not escape HTML, and grant the user
|
||||
// access to it.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$edit = [
|
||||
'format' => Unicode::strtolower($this->randomMachineName()),
|
||||
'format' => mb_strtolower($this->randomMachineName()),
|
||||
'name' => $this->randomMachineName(),
|
||||
];
|
||||
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
|
||||
|
@ -238,8 +243,8 @@ class TextFieldTest extends StringFieldTest {
|
|||
$entity = EntityTest::load($id);
|
||||
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
|
||||
$content = $display->build($entity);
|
||||
$this->setRawContent($renderer->renderRoot($content));
|
||||
$this->assertRaw($value, 'Value is displayed unfiltered');
|
||||
$rendered_entity = \Drupal::service('renderer')->renderRoot($content);
|
||||
$this->assertContains($value, (string) $rendered_entity);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\FunctionalJavascript;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* Tests the JavaScript functionality of the text_textarea_with_summary widget.
|
||||
*
|
||||
* @group text
|
||||
*/
|
||||
class TextareaWithSummaryTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['text', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
|
||||
$account = $this->drupalCreateUser(['create page content', 'edit own page content']);
|
||||
$this->drupalLogin($account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to test toggling the summary area.
|
||||
*/
|
||||
protected function assertSummaryToggle() {
|
||||
$this->drupalGet('node/add/page');
|
||||
$widget = $this->getSession()->getPage()->findById('edit-body-wrapper');
|
||||
$summary_field = $widget->findField('edit-body-0-summary');
|
||||
|
||||
$this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden by default.');
|
||||
$this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'No Hide summary link by default.');
|
||||
|
||||
$widget->pressButton('Edit summary');
|
||||
$this->assertEquals(FALSE, $widget->hasButton('Edit summary'), 'Edit summary link is removed after clicking.');
|
||||
$this->assertEquals(TRUE, $summary_field->isVisible(), 'Summary field is shown.');
|
||||
|
||||
$widget->pressButton('Hide summary');
|
||||
$this->assertEquals(FALSE, $widget->hasButton('Hide summary'), 'Hide summary link is removed after clicking.');
|
||||
$this->assertEquals(FALSE, $summary_field->isVisible(), 'Summary field is hidden again.');
|
||||
$this->assertEquals(TRUE, $widget->hasButton('Edit summary'), 'Edit summary link is visible again.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the textSummary javascript behavior.
|
||||
*/
|
||||
public function testTextSummaryBehavior() {
|
||||
// Test with field defaults.
|
||||
$this->assertSummaryToggle();
|
||||
|
||||
// Repeat test with non-empty field description.
|
||||
$body_field = FieldConfig::loadByName('node', 'page', 'body');
|
||||
$body_field->set('description', 'Text with Summary field description.');
|
||||
$body_field->save();
|
||||
|
||||
$this->assertSummaryToggle();
|
||||
|
||||
// Test summary is shown when non-empty.
|
||||
$node = $this->createNode([
|
||||
'body' => [
|
||||
[
|
||||
'value' => $this->randomMachineName(32),
|
||||
'summary' => $this->randomMachineName(32),
|
||||
'format' => filter_default_format(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||
$page = $this->getSession()->getPage();
|
||||
$summary_field = $page->findField('edit-body-0-summary');
|
||||
|
||||
$this->assertEquals(TRUE, $summary_field->isVisible(), 'Non-empty summary field is shown by default.');
|
||||
}
|
||||
|
||||
}
|
|
@ -35,10 +35,15 @@ class TextSummaryTest extends KernelTestBase {
|
|||
* Test summary with long example.
|
||||
*/
|
||||
public function testLongSentence() {
|
||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' . // 125
|
||||
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' . // 108
|
||||
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' . // 103
|
||||
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; // 110
|
||||
// 125.
|
||||
$text =
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' .
|
||||
// 108.
|
||||
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' .
|
||||
// 103.
|
||||
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' .
|
||||
// 110.
|
||||
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
|
||||
$expected = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' .
|
||||
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' .
|
||||
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
|
||||
|
@ -202,6 +207,15 @@ class TextSummaryTest extends KernelTestBase {
|
|||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test text_summary() returns an empty string without any error when called
|
||||
* with an invalid format.
|
||||
*/
|
||||
public function testInvalidFilterFormat() {
|
||||
|
||||
$this->assertTextSummary($this->randomString(100), '', 'non_existent_format');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls text_summary() and asserts that the expected teaser is returned.
|
||||
*/
|
||||
|
|
|
@ -26,7 +26,7 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
|
|||
/**
|
||||
* Field storage entity.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig.
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
|
@ -37,7 +37,6 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
|
|||
*/
|
||||
protected $field;
|
||||
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
|
@ -106,7 +105,7 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
|
|||
'type' => 'text_with_summary',
|
||||
'settings' => [
|
||||
'max_length' => 10,
|
||||
]
|
||||
],
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
|
|
|
@ -11,8 +11,9 @@ use Prophecy\Argument;
|
|||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextFieldTest extends UnitTestCase {
|
||||
class TextCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
|
@ -37,7 +38,7 @@ class TextFieldTest extends UnitTestCase {
|
|||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function($arguments) use ($migration) {
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
|
@ -54,7 +55,7 @@ class TextFieldTest extends UnitTestCase {
|
|||
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('iterator', $process['plugin']);
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
|
@ -75,7 +76,7 @@ class TextFieldTest extends UnitTestCase {
|
|||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
]
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
|
@ -100,7 +101,7 @@ class TextFieldTest extends UnitTestCase {
|
|||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
]
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
|
@ -122,37 +123,33 @@ class TextFieldTest extends UnitTestCase {
|
|||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
]],
|
||||
['string_long', 'text_textfield', ['text_processing' => FALSE]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
]],
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
]],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
]],
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', ['text_processing' => TRUE]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
]],
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
]],
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea', [
|
||||
'text_processing' => TRUE,
|
||||
]],
|
||||
['string_long', 'text_textarea', [
|
||||
'text_processing' => FALSE,
|
||||
]],
|
||||
['text_long', 'text_textarea', ['text_processing' => TRUE]],
|
||||
['string_long', 'text_textarea', ['text_processing' => FALSE]],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
@ -162,8 +159,7 @@ class TextFieldTest extends UnitTestCase {
|
|||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
|
@ -0,0 +1,253 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\text\Plugin\migrate\field\d6\TextField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TextField([], 'text', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's defineValueProcessPipeline() method will call
|
||||
// setProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the deprecated processFieldValues() method to test BC.
|
||||
*
|
||||
* @covers ::processFieldValues
|
||||
*
|
||||
* @depends testFilteredTextValueProcessPipeline
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues() {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->processFieldValues($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testFilteredTextValueProcessPipeline() {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->defineValueProcessPipeline($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the deprecated processFieldValues() method to test BC.
|
||||
*
|
||||
* @covers ::processFieldValues
|
||||
*
|
||||
* @depends testBooleanTextImplicitValueProcessPipeline
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
],
|
||||
];
|
||||
$this->plugin->processFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testBooleanTextImplicitValueProcessPipeline() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
],
|
||||
];
|
||||
$this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the deprecated processFieldValues() method to test BC.
|
||||
*
|
||||
* @covers ::processFieldValues
|
||||
*
|
||||
* @depends testBooleanTextExplicitValueProcessPipeline
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
],
|
||||
];
|
||||
$this->plugin->processFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testBooleanTextExplicitValueProcessPipeline() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
],
|
||||
];
|
||||
$this->plugin->defineValueProcessPipeline($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['string_long', 'text_textfield', ['text_processing' => FALSE]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', ['text_processing' => TRUE]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea', ['text_processing' => TRUE]],
|
||||
['string_long', 'text_textarea', ['text_processing' => FALSE]],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\text\Unit\Migrate\d6\TextFieldTest as D6TextFieldTest;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d7\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextFieldTest extends D6TextFieldTest {}
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\text\Plugin\migrate\cckfield\TextField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextCckTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TextField([], 'text', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processCckFieldValues() method will call
|
||||
// setProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues() {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues() {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
],
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['string_long', 'text_textfield', ['text_processing' => FALSE]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', ['text_processing' => TRUE]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea', ['text_processing' => TRUE]],
|
||||
['string_long', 'text_textarea', ['text_processing' => FALSE]],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row(['widget_type' => $widget_type], ['widget_type' => []]);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Plugin\migrate\field\d6;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
|
||||
* @group text
|
||||
* @group legacy
|
||||
*/
|
||||
class TextFieldLegacyTest extends TextFieldTest {
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues($method = 'processFieldValues') {
|
||||
parent::testProcessFilteredTextFieldValues($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues($method = 'processFieldValues') {
|
||||
parent::testProcessBooleanTextImplicitValues($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processFieldValues
|
||||
* @expectedDeprecation Deprecated in Drupal 8.6.0, to be removed before Drupal 9.0.0. Use defineValueProcessPipeline() instead. See https://www.drupal.org/node/2944598.
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues($method = 'processFieldValues') {
|
||||
parent::testProcessBooleanTextExplicitValues($method);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Plugin\migrate\field\d6;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\text\Plugin\migrate\field\d6\TextField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d6\TextField
|
||||
* @group text
|
||||
*/
|
||||
class TextFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TextField([], 'text', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's defineValueProcessPipeline() method will call
|
||||
// setProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function ($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues($method = 'defineValueProcessPipeline') {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->$method($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('sub_process', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues($method = 'defineValueProcessPipeline') {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
],
|
||||
];
|
||||
$this->plugin->$method($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::defineValueProcessPipeline
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues($method = 'defineValueProcessPipeline') {
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
],
|
||||
];
|
||||
$this->plugin->$method($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return [
|
||||
['string_long', 'text_textfield', ['text_processing' => FALSE]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', ['text_processing' => TRUE]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
],
|
||||
],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
],
|
||||
],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea', ['text_processing' => TRUE]],
|
||||
['string_long', 'text_textarea', ['text_processing' => FALSE]],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = []) {
|
||||
$row = new Row();
|
||||
$row->setSourceProperty('widget_type', $widget_type);
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Plugin\migrate\field\d7;
|
||||
|
||||
use Drupal\Tests\text\Unit\Plugin\migrate\field\d6\TextFieldTest as D6TextFieldTest;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\field\d7\TextField
|
||||
* @group text
|
||||
*/
|
||||
class TextFieldTest extends D6TextFieldTest {}
|
65
web/core/modules/text/text.es6.js
Normal file
65
web/core/modules/text/text.es6.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @file
|
||||
* Text behaviors.
|
||||
*/
|
||||
|
||||
(function($, Drupal) {
|
||||
/**
|
||||
* Auto-hide summary textarea if empty and show hide and unhide links.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches auto-hide behavior on `text-summary` events.
|
||||
*/
|
||||
Drupal.behaviors.textSummary = {
|
||||
attach(context, settings) {
|
||||
$(context)
|
||||
.find('.js-text-summary')
|
||||
.once('text-summary')
|
||||
.each(function() {
|
||||
const $widget = $(this).closest('.js-text-format-wrapper');
|
||||
|
||||
const $summary = $widget.find('.js-text-summary-wrapper');
|
||||
const $summaryLabel = $summary.find('label').eq(0);
|
||||
const $full = $widget.children('.js-form-type-textarea');
|
||||
let $fullLabel = $full.find('label').eq(0);
|
||||
|
||||
// Create a placeholder label when the field cardinality is greater
|
||||
// than 1.
|
||||
if ($fullLabel.length === 0) {
|
||||
$fullLabel = $('<label></label>').prependTo($full);
|
||||
}
|
||||
|
||||
// Set up the edit/hide summary link.
|
||||
const $link = $(
|
||||
`<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">${Drupal.t(
|
||||
'Hide summary',
|
||||
)}</button>)</span>`,
|
||||
);
|
||||
const $button = $link.find('button');
|
||||
let toggleClick = true;
|
||||
$link
|
||||
.on('click', e => {
|
||||
if (toggleClick) {
|
||||
$summary.hide();
|
||||
$button.html(Drupal.t('Edit summary'));
|
||||
$link.appendTo($fullLabel);
|
||||
} else {
|
||||
$summary.show();
|
||||
$button.html(Drupal.t('Hide summary'));
|
||||
$link.appendTo($summaryLabel);
|
||||
}
|
||||
e.preventDefault();
|
||||
toggleClick = !toggleClick;
|
||||
})
|
||||
.appendTo($summaryLabel);
|
||||
|
||||
// If no summary is set, hide the summary field.
|
||||
if ($widget.find('.js-text-summary').val() === '') {
|
||||
$link.trigger('click');
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal);
|
|
@ -5,5 +5,5 @@ package: Field types
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- field
|
||||
- filter
|
||||
- drupal:field
|
||||
- drupal:filter
|
||||
|
|
|
@ -1,37 +1,25 @@
|
|||
/**
|
||||
* @file
|
||||
* Text behaviors.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Auto-hide summary textarea if empty and show hide and unhide links.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches auto-hide behavior on `text-summary` events.
|
||||
*/
|
||||
Drupal.behaviors.textSummary = {
|
||||
attach: function (context, settings) {
|
||||
attach: function attach(context, settings) {
|
||||
$(context).find('.js-text-summary').once('text-summary').each(function () {
|
||||
var $widget = $(this).closest('.js-text-format-wrapper');
|
||||
|
||||
var $summary = $widget.find('.js-text-summary-wrapper');
|
||||
var $summaryLabel = $summary.find('label').eq(0);
|
||||
var $full = $widget.find('.js-text-full').closest('.js-form-item');
|
||||
var $full = $widget.children('.js-form-type-textarea');
|
||||
var $fullLabel = $full.find('label').eq(0);
|
||||
|
||||
// Create a placeholder label when the field cardinality is greater
|
||||
// than 1.
|
||||
if ($fullLabel.length === 0) {
|
||||
$fullLabel = $('<label></label>').prependTo($full);
|
||||
}
|
||||
|
||||
// Set up the edit/hide summary link.
|
||||
var $link = $('<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">' + Drupal.t('Hide summary') + '</button>)</span>');
|
||||
var $button = $link.find('button');
|
||||
var toggleClick = true;
|
||||
|
@ -40,8 +28,7 @@
|
|||
$summary.hide();
|
||||
$button.html(Drupal.t('Edit summary'));
|
||||
$link.appendTo($fullLabel);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$summary.show();
|
||||
$button.html(Drupal.t('Hide summary'));
|
||||
$link.appendTo($summaryLabel);
|
||||
|
@ -50,12 +37,10 @@
|
|||
toggleClick = !toggleClick;
|
||||
}).appendTo($summaryLabel);
|
||||
|
||||
// If no summary is set, hide the summary field.
|
||||
if ($widget.find('.js-text-summary').val() === '') {
|
||||
$link.trigger('click');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, Drupal);
|
||||
})(jQuery, Drupal);
|
|
@ -81,17 +81,17 @@ function text_summary($text, $format = NULL, $size = NULL) {
|
|||
|
||||
// Retrieve the filters of the specified text format, if any.
|
||||
if (isset($format)) {
|
||||
$filters = FilterFormat::load($format)->filters();
|
||||
$filter_format = FilterFormat::load($format);
|
||||
// If the specified format does not exist, return nothing. $text is already
|
||||
// filtered text, but the remainder of this function will not be able to
|
||||
// ensure a sane and secure summary.
|
||||
if (!$filters) {
|
||||
if (!$filter_format || !($filters = $filter_format->filters())) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// If we have a short body, the entire body is the summary.
|
||||
if (Unicode::strlen($text) <= $size) {
|
||||
if (mb_strlen($text) <= $size) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue