Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -16,4 +16,4 @@ namespace Drupal\text\Plugin\Field\FieldFormatter;
* }
* )
*/
class TextSummaryOrTrimmedFormatter extends TextTrimmedFormatter { }
class TextSummaryOrTrimmedFormatter extends TextTrimmedFormatter {}

View file

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

View file

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

View file

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

View file

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

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

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

View file

@ -1,245 +0,0 @@
<?php
namespace Drupal\text\Tests;
use Drupal\Component\Utility\Unicode;
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;
/**
* Tests the creation of text fields.
*
* @group text
*/
class TextFieldTest extends StringFieldTest {
/**
* A user with relevant administrative privileges.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(['administer filters']);
}
// Test fields.
/**
* Test text field validation.
*/
public function testTextFieldValidation() {
// Create a field with settings to validate.
$max_length = 3;
$field_name = Unicode::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([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
])->save();
// Test validation with valid and invalid values.
$entity = EntityTest::create();
for ($i = 0; $i <= $max_length + 2; $i++) {
$entity->{$field_name}->value = str_repeat('x', $i);
$violations = $entity->{$field_name}->validate();
if ($i <= $max_length) {
$this->assertEqual(count($violations), 0, "Length $i does not cause validation error when max_length is $max_length");
}
else {
$this->assertEqual(count($violations), 1, "Length $i causes validation error when max_length is $max_length");
}
}
}
/**
* Test required long text with file upload.
*/
public function testRequiredLongTextWithFileUpload() {
// Create a text field.
$text_field_name = 'text_long';
$field_storage = FieldStorageConfig::create([
'field_name' => $text_field_name,
'entity_type' => 'entity_test',
'type' => 'text_with_summary',
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
'required' => TRUE,
])->save();
// Create a file field.
$file_field_name = 'file_field';
$field_storage = FieldStorageConfig::create([
'field_name' => $file_field_name,
'entity_type' => 'entity_test',
'type' => 'file'
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($text_field_name, [
'type' => 'text_textarea_with_summary',
])
->setComponent($file_field_name, [
'type' => 'file_generic',
])
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($text_field_name)
->setComponent($file_field_name)
->save();
$test_file = current($this->drupalGetTestFiles('text'));
$edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
$this->drupalPostForm('entity_test/add', $edit, 'Upload');
$this->assertResponse(200);
$edit = [
'text_long[0][value]' => 'Long text'
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertResponse(200);
$this->drupalGet('entity_test/1');
$this->assertText('Long text');
}
/**
* Test widgets.
*/
public function testTextfieldWidgets() {
$this->_testTextfieldWidgets('text', 'text_textfield');
$this->_testTextfieldWidgets('text_long', 'text_textarea');
}
/**
* Test widgets + 'formatted_text' setting.
*/
public function testTextfieldWidgetsFormatted() {
$this->_testTextfieldWidgetsFormatted('text', 'text_textfield');
$this->_testTextfieldWidgetsFormatted('text_long', 'text_textarea');
}
/**
* Helper function for testTextfieldWidgetsFormatted().
*/
public function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
// Create a field.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $field_type
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this->randomMachineName() . '_label',
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, [
'type' => $widget_type,
])
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($field_name)
->save();
// Disable all text formats besides the plain text fallback format.
$this->drupalLogin($this->adminUser);
foreach (filter_formats() as $format) {
if (!$format->isFallbackFormat()) {
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
}
}
$this->drupalLogin($this->webUser);
// Display the creation form. Since the user only has access to one format,
// no format selector will be displayed.
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed');
$this->assertNoFieldByName("{$field_name}[0][format]", '', 'Format selector is not displayed');
// Submit with data that should be filtered.
$value = '<em>' . $this->randomMachineName() . '</em>';
$edit = [
"{$field_name}[0][value]" => $value,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
// Display the entity.
$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.');
// 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()),
'name' => $this->randomMachineName(),
];
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
filter_formats_reset();
$format = FilterFormat::load($edit['format']);
$format_id = $format->id();
$permission = $format->getPermissionName();
$roles = $this->webUser->getRoles();
$rid = $roles[0];
user_role_grant_permissions($rid, [$permission]);
$this->drupalLogin($this->webUser);
// Display edition form.
// We should now have a 'text format' selector.
$this->drupalGet('entity_test/manage/' . $id . '/edit');
$this->assertFieldByName("{$field_name}[0][value]", NULL, 'Widget is displayed');
$this->assertFieldByName("{$field_name}[0][format]", NULL, 'Format selector is displayed');
// Edit and change the text format to the new one that was created.
$edit = [
"{$field_name}[0][format]" => $format_id,
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('entity_test @id has been updated.', ['@id' => $id]), 'Entity was updated');
// Display the entity.
$this->container->get('entity.manager')->getStorage('entity_test')->resetCache([$id]);
$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');
}
}

View file

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