Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -24,17 +24,17 @@ class TextDefaultFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$elements = [];
// The ProcessedText element already handles cache context & tag bubbling.
// @see \Drupal\filter\Element\ProcessedText::preRenderText()
foreach ($items as $delta => $item) {
$elements[$delta] = array(
$elements[$delta] = [
'#type' => 'processed_text',
'#text' => $item->value,
'#format' => $item->format,
'#langcode' => $item->getLangcode(),
);
];
}
return $elements;

View file

@ -33,24 +33,24 @@ class TextTrimmedFormatter extends FormatterBase {
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
return [
'trim_length' => '600',
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['trim_length'] = array(
$element['trim_length'] = [
'#title' => t('Trimmed limit'),
'#type' => 'number',
'#field_suffix' => t('characters'),
'#default_value' => $this->getSetting('trim_length'),
'#description' => t('If the summary is not set, the trimmed %label field will end at the last full sentence before this character limit.', array('%label' => $this->fieldDefinition->getLabel())),
'#description' => t('If the summary is not set, the trimmed %label field will end at the last full sentence before this character limit.', ['%label' => $this->fieldDefinition->getLabel()]),
'#min' => 1,
'#required' => TRUE,
);
];
return $element;
}
@ -58,8 +58,8 @@ class TextTrimmedFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$summary[] = t('Trimmed limit: @trim_length characters', array('@trim_length' => $this->getSetting('trim_length')));
$summary = [];
$summary[] = t('Trimmed limit: @trim_length characters', ['@trim_length' => $this->getSetting('trim_length')]);
return $summary;
}
@ -67,7 +67,7 @@ class TextTrimmedFormatter extends FormatterBase {
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$elements = [];
$render_as_summary = function (&$element) {
// Make sure any default #pre_render callbacks are set on the element,
@ -82,12 +82,12 @@ class TextTrimmedFormatter extends FormatterBase {
// The ProcessedText element already handles cache context & tag bubbling.
// @see \Drupal\filter\Element\ProcessedText::preRenderText()
foreach ($items as $delta => $item) {
$elements[$delta] = array(
$elements[$delta] = [
'#type' => 'processed_text',
'#text' => NULL,
'#format' => $item->format,
'#langcode' => $item->getLangcode(),
);
];
if ($this->getPluginId() == 'text_summary_or_trimmed' && !empty($item->summary)) {
$elements[$delta]['#text'] = $item->summary;

View file

@ -23,30 +23,30 @@ class TextItem extends TextItemBase {
* {@inheritdoc}
*/
public static function defaultStorageSettings() {
return array(
return [
'max_length' => 255,
) + parent::defaultStorageSettings();
] + parent::defaultStorageSettings();
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => $field_definition->getSetting('max_length'),
),
'format' => array(
],
'format' => [
'type' => 'varchar',
'length' => 255,
),
),
'indexes' => array(
'format' => array('format'),
),
);
],
],
'indexes' => [
'format' => ['format'],
],
];
}
/**
@ -57,14 +57,14 @@ class TextItem extends TextItemBase {
$constraints = parent::getConstraints();
if ($max_length = $this->getSetting('max_length')) {
$constraints[] = $constraint_manager->create('ComplexData', array(
'value' => array(
'Length' => array(
$constraints[] = $constraint_manager->create('ComplexData', [
'value' => [
'Length' => [
'max' => $max_length,
'maxMessage' => t('%name: the text may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length)),
)
),
));
'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]),
]
],
]);
}
return $constraints;
@ -74,9 +74,9 @@ class TextItem extends TextItemBase {
* {@inheritdoc}
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = array();
$element = [];
$element['max_length'] = array(
$element['max_length'] = [
'#type' => 'number',
'#title' => t('Maximum length'),
'#default_value' => $this->getSetting('max_length'),
@ -84,7 +84,7 @@ class TextItem extends TextItemBase {
'#description' => t('The maximum length of the field in characters.'),
'#min' => 1,
'#disabled' => $has_data,
);
];
$element += parent::storageSettingsForm($form, $form_state, $has_data);
return $element;

View file

@ -39,7 +39,7 @@ abstract class TextItemBase extends FieldItemBase {
*/
public function applyDefaultValue($notify = TRUE) {
// @todo: Add in the filter default format here.
$this->setValue(array('format' => NULL), $notify);
$this->setValue(['format' => NULL], $notify);
return $this;
}
@ -82,11 +82,11 @@ abstract class TextItemBase extends FieldItemBase {
$value = substr($random->sentences(mt_rand(1, $settings['max_length'] / 3), FALSE), 0, $settings['max_length']);
}
$values = array(
$values = [
'value' => $value,
'summary' => $value,
'format' => filter_fallback_format(),
);
];
return $values;
}

View file

@ -22,21 +22,21 @@ class TextLongItem extends TextItemBase {
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
return [
'columns' => [
'value' => [
'type' => 'text',
'size' => 'big',
),
'format' => array(
],
'format' => [
'type' => 'varchar_ascii',
'length' => 255,
),
),
'indexes' => array(
'format' => array('format'),
),
);
],
],
'indexes' => [
'format' => ['format'],
],
];
}
}

View file

@ -24,9 +24,9 @@ class TextWithSummaryItem extends TextItemBase {
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
return array(
return [
'display_summary' => 0,
) + parent::defaultFieldSettings();
] + parent::defaultFieldSettings();
}
/**
@ -52,25 +52,25 @@ class TextWithSummaryItem extends TextItemBase {
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
return [
'columns' => [
'value' => [
'type' => 'text',
'size' => 'big',
),
'summary' => array(
],
'summary' => [
'type' => 'text',
'size' => 'big',
),
'format' => array(
],
'format' => [
'type' => 'varchar_ascii',
'length' => 255,
),
),
'indexes' => array(
'format' => array('format'),
),
);
],
],
'indexes' => [
'format' => ['format'],
],
];
}
/**
@ -85,15 +85,15 @@ class TextWithSummaryItem extends TextItemBase {
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array();
$element = [];
$settings = $this->getSettings();
$element['display_summary'] = array(
$element['display_summary'] = [
'#type' => 'checkbox',
'#title' => t('Summary input'),
'#default_value' => $settings['display_summary'],
'#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'),
);
];
return $element;
}

View file

@ -20,6 +20,15 @@ use Symfony\Component\Validator\ConstraintViolationInterface;
*/
class TextareaWidget extends StringTextareaWidget {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$element['rows']['#description'] = $this->t('Text editors (like CKEditor) may override this setting.');
return $element;
}
/**
* {@inheritdoc}
*/
@ -37,7 +46,7 @@ class TextareaWidget extends StringTextareaWidget {
* {@inheritdoc}
*/
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
if ($violation->arrayPropertyPath == array('format') && isset($element['format']['#access']) && !$element['format']['#access']) {
if ($violation->arrayPropertyPath == ['format'] && isset($element['format']['#access']) && !$element['format']['#access']) {
// Ignore validation errors for formats if formats may not be changed,
// i.e. when existing formats become invalid. See filter_process_format().
return FALSE;

View file

@ -23,11 +23,11 @@ class TextareaWithSummaryWidget extends TextareaWidget {
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
return [
'rows' => '9',
'summary_rows' => '3',
'placeholder' => '',
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
@ -35,13 +35,14 @@ class TextareaWithSummaryWidget extends TextareaWidget {
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$element['summary_rows'] = array(
$element['summary_rows'] = [
'#type' => 'number',
'#title' => t('Summary rows'),
'#default_value' => $this->getSetting('summary_rows'),
'#description' => $element['rows']['#description'],
'#required' => TRUE,
'#min' => 1,
);
];
return $element;
}
@ -51,7 +52,7 @@ class TextareaWithSummaryWidget extends TextareaWidget {
public function settingsSummary() {
$summary = parent::settingsSummary();
$summary[] = t('Number of summary rows: @rows', array('@rows' => $this->getSetting('summary_rows')));
$summary[] = t('Number of summary rows: @rows', ['@rows' => $this->getSetting('summary_rows')]);
return $summary;
}
@ -59,24 +60,24 @@ class TextareaWithSummaryWidget extends TextareaWidget {
/**
* {@inheritdoc}
*/
function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$display_summary = $items[$delta]->summary || $this->getFieldSetting('display_summary');
$element['summary'] = array(
$element['summary'] = [
'#type' => $display_summary ? 'textarea' : 'value',
'#default_value' => $items[$delta]->summary,
'#title' => t('Summary'),
'#rows' => $this->getSetting('summary_rows'),
'#description' => t('Leave blank to use trimmed value of full text as the summary.'),
'#attached' => array(
'library' => array('text/drupal.text'),
),
'#attributes' => array('class' => array('js-text-summary', 'text-summary')),
'#attached' => [
'library' => ['text/drupal.text'],
],
'#attributes' => ['class' => ['js-text-summary', 'text-summary']],
'#prefix' => '<div class="js-text-summary-wrapper text-summary-wrapper">',
'#suffix' => '</div>',
'#weight' => -10,
);
];
return $element;
}

View file

@ -37,7 +37,7 @@ class TextfieldWidget extends StringTextfieldWidget {
* {@inheritdoc}
*/
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
if ($violation->arrayPropertyPath == array('format') && isset($element['format']['#access']) && !$element['format']['#access']) {
if ($violation->arrayPropertyPath == ['format'] && isset($element['format']['#access']) && !$element['format']['#access']) {
// Ignore validation errors for formats if formats may not be changed,
// i.e. when existing formats become invalid. See filter_process_format().
return FALSE;

View file

@ -87,11 +87,11 @@ class TextField extends CckFieldPluginBase {
];
}
$process = array(
$process = [
'plugin' => 'iterator',
'source' => $field_name,
'process' => $process,
);
];
$migration->setProcessOfProperty($field_name, $process);
}

View file

@ -26,7 +26,7 @@ class TextFieldTest extends StringFieldTest {
protected function setUp() {
parent::setUp();
$this->adminUser = $this->drupalCreateUser(array('administer filters'));
$this->adminUser = $this->drupalCreateUser(['administer filters']);
}
// Test fields.
@ -34,18 +34,18 @@ class TextFieldTest extends StringFieldTest {
/**
* Test text field validation.
*/
function testTextFieldValidation() {
public function testTextFieldValidation() {
// Create a field with settings to validate.
$max_length = 3;
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text',
'settings' => array(
'settings' => [
'max_length' => $max_length,
)
));
]
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
@ -69,14 +69,14 @@ class TextFieldTest extends StringFieldTest {
/**
* Test required long text with file upload.
*/
function testRequiredLongTextWithFileUpload() {
public function testRequiredLongTextWithFileUpload() {
// Create a text field.
$text_field_name = 'text_long';
$field_storage = FieldStorageConfig::create(array(
$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,
@ -87,11 +87,11 @@ class TextFieldTest extends StringFieldTest {
// Create a file field.
$file_field_name = 'file_field';
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $file_field_name,
'entity_type' => 'entity_test',
'type' => 'file'
));
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
@ -100,12 +100,12 @@ class TextFieldTest extends StringFieldTest {
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($text_field_name, array(
->setComponent($text_field_name, [
'type' => 'text_textarea_with_summary',
))
->setComponent($file_field_name, array(
])
->setComponent($file_field_name, [
'type' => 'file_generic',
))
])
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($text_field_name)
@ -116,9 +116,9 @@ class TextFieldTest extends StringFieldTest {
$edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
$this->drupalPostForm('entity_test/add', $edit, 'Upload');
$this->assertResponse(200);
$edit = array(
$edit = [
'text_long[0][value]' => 'Long text'
);
];
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertResponse(200);
$this->drupalGet('entity_test/1');
@ -128,7 +128,7 @@ class TextFieldTest extends StringFieldTest {
/**
* Test widgets.
*/
function testTextfieldWidgets() {
public function testTextfieldWidgets() {
$this->_testTextfieldWidgets('text', 'text_textfield');
$this->_testTextfieldWidgets('text_long', 'text_textarea');
}
@ -136,7 +136,7 @@ class TextFieldTest extends StringFieldTest {
/**
* Test widgets + 'formatted_text' setting.
*/
function testTextfieldWidgetsFormatted() {
public function testTextfieldWidgetsFormatted() {
$this->_testTextfieldWidgetsFormatted('text', 'text_textfield');
$this->_testTextfieldWidgetsFormatted('text_long', 'text_textarea');
}
@ -144,17 +144,17 @@ class TextFieldTest extends StringFieldTest {
/**
* Helper function for testTextfieldWidgetsFormatted().
*/
function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
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(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => $field_type
));
]);
$field_storage->save();
FieldConfig::create([
'field_storage' => $field_storage,
@ -162,9 +162,9 @@ class TextFieldTest extends StringFieldTest {
'label' => $this->randomMachineName() . '_label',
])->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => $widget_type,
))
])
->save();
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($field_name)
@ -174,7 +174,7 @@ class TextFieldTest extends StringFieldTest {
$this->drupalLogin($this->adminUser);
foreach (filter_formats() as $format) {
if (!$format->isFallbackFormat()) {
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', array(), t('Disable'));
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', [], t('Disable'));
}
}
$this->drupalLogin($this->webUser);
@ -187,13 +187,13 @@ class TextFieldTest extends StringFieldTest {
// Submit with data that should be filtered.
$value = '<em>' . $this->randomMachineName() . '</em>';
$edit = array(
$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.', array('@id' => $id)), 'Entity was created');
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
// Display the entity.
$entity = EntityTest::load($id);
@ -206,10 +206,10 @@ class TextFieldTest extends StringFieldTest {
// Create a new text format that does not escape HTML, and grant the user
// access to it.
$this->drupalLogin($this->adminUser);
$edit = array(
$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']);
@ -217,7 +217,7 @@ class TextFieldTest extends StringFieldTest {
$permission = $format->getPermissionName();
$roles = $this->webUser->getRoles();
$rid = $roles[0];
user_role_grant_permissions($rid, array($permission));
user_role_grant_permissions($rid, [$permission]);
$this->drupalLogin($this->webUser);
// Display edition form.
@ -227,14 +227,14 @@ class TextFieldTest extends StringFieldTest {
$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 = array(
$edit = [
"{$field_name}[0][format]" => $format_id,
);
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated');
$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(array($id));
$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);