Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -87,11 +87,11 @@ class TextField extends CckFieldPluginBase {
|
|||
];
|
||||
}
|
||||
|
||||
$process = array(
|
||||
$process = [
|
||||
'plugin' => 'iterator',
|
||||
'source' => $field_name,
|
||||
'process' => $process,
|
||||
);
|
||||
];
|
||||
$migration->setProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\text\Kernel\Migrate;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,7 +33,7 @@ class TextFormatterTest extends EntityKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('text');
|
||||
public static $modules = ['text'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -41,23 +41,23 @@ class TextFormatterTest extends EntityKernelTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
FilterFormat::create(array(
|
||||
FilterFormat::create([
|
||||
'format' => 'my_text_format',
|
||||
'name' => 'My text format',
|
||||
'filters' => array(
|
||||
'filter_autop' => array(
|
||||
'filters' => [
|
||||
'filter_autop' => [
|
||||
'module' => 'filter',
|
||||
'status' => TRUE,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
],
|
||||
],
|
||||
])->save();
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => 'formatted_text',
|
||||
'entity_type' => $this->entityType,
|
||||
'type' => 'text',
|
||||
'settings' => array(),
|
||||
))->save();
|
||||
'settings' => [],
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityType,
|
||||
'bundle' => $this->bundle,
|
||||
|
@ -70,28 +70,28 @@ class TextFormatterTest extends EntityKernelTestBase {
|
|||
* Tests all text field formatters.
|
||||
*/
|
||||
public function testFormatters() {
|
||||
$formatters = array(
|
||||
$formatters = [
|
||||
'text_default',
|
||||
'text_trimmed',
|
||||
'text_summary_or_trimmed',
|
||||
);
|
||||
];
|
||||
|
||||
// Create the entity to be referenced.
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityType)
|
||||
->create(array('name' => $this->randomMachineName()));
|
||||
$entity->formatted_text = array(
|
||||
->create(['name' => $this->randomMachineName()]);
|
||||
$entity->formatted_text = [
|
||||
'value' => 'Hello, world!',
|
||||
'format' => 'my_text_format',
|
||||
);
|
||||
];
|
||||
$entity->save();
|
||||
|
||||
foreach ($formatters as $formatter) {
|
||||
// Verify the text field formatter's render array.
|
||||
$build = $entity->get('formatted_text')->view(array('type' => $formatter));
|
||||
$build = $entity->get('formatted_text')->view(['type' => $formatter]);
|
||||
\Drupal::service('renderer')->renderRoot($build[0]);
|
||||
$this->assertEqual($build[0]['#markup'], "<p>Hello, world!</p>\n");
|
||||
$this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter)));
|
||||
$this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', ['@formatter' => $formatter]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,12 @@ use Drupal\filter\Entity\FilterFormat;
|
|||
*/
|
||||
class TextSummaryTest extends KernelTestBase {
|
||||
|
||||
public static $modules = array('system', 'user', 'filter', 'text');
|
||||
public static $modules = ['system', 'user', 'filter', 'text'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('text'));
|
||||
$this->installConfig(['text']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ class TextSummaryTest extends KernelTestBase {
|
|||
* subsequent sentences are not. This edge case is documented at
|
||||
* https://www.drupal.org/node/180425.
|
||||
*/
|
||||
function testFirstSentenceQuestion() {
|
||||
public function testFirstSentenceQuestion() {
|
||||
$text = 'A question? A sentence. Another sentence.';
|
||||
$expected = 'A question? A sentence.';
|
||||
$this->assertTextSummary($text, $expected, NULL, 30);
|
||||
|
@ -34,7 +34,7 @@ class TextSummaryTest extends KernelTestBase {
|
|||
/**
|
||||
* Test summary with long example.
|
||||
*/
|
||||
function testLongSentence() {
|
||||
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
|
||||
|
@ -49,26 +49,26 @@ class TextSummaryTest extends KernelTestBase {
|
|||
/**
|
||||
* Test various summary length edge cases.
|
||||
*/
|
||||
function testLength() {
|
||||
FilterFormat::create(array(
|
||||
public function testLength() {
|
||||
FilterFormat::create([
|
||||
'format' => 'autop',
|
||||
'filters' => array(
|
||||
'filter_autop' => array(
|
||||
'filters' => [
|
||||
'filter_autop' => [
|
||||
'status' => 1,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
FilterFormat::create(array(
|
||||
],
|
||||
],
|
||||
])->save();
|
||||
FilterFormat::create([
|
||||
'format' => 'autop_correct',
|
||||
'filters' => array(
|
||||
'filter_autop' => array(
|
||||
'filters' => [
|
||||
'filter_autop' => [
|
||||
'status' => 1,
|
||||
),
|
||||
'filter_htmlcorrector' => array(
|
||||
],
|
||||
'filter_htmlcorrector' => [
|
||||
'status' => 1,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
],
|
||||
],
|
||||
])->save();
|
||||
|
||||
// This string tests a number of edge cases.
|
||||
$text = "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>";
|
||||
|
@ -205,12 +205,12 @@ class TextSummaryTest extends KernelTestBase {
|
|||
/**
|
||||
* Calls text_summary() and asserts that the expected teaser is returned.
|
||||
*/
|
||||
function assertTextSummary($text, $expected, $format = NULL, $size = NULL) {
|
||||
public function assertTextSummary($text, $expected, $format = NULL, $size = NULL) {
|
||||
$summary = text_summary($text, $format, $size);
|
||||
$this->assertIdentical($summary, $expected, format_string('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', array(
|
||||
$this->assertIdentical($summary, $expected, format_string('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', [
|
||||
'@actual' => $summary,
|
||||
'@expected' => $expected,
|
||||
)));
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('filter');
|
||||
public static $modules = ['filter'];
|
||||
|
||||
/**
|
||||
* Field storage entity.
|
||||
|
@ -44,11 +44,11 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
|
|||
$this->installEntitySchema('entity_test_rev');
|
||||
|
||||
// Create the necessary formats.
|
||||
$this->installConfig(array('filter'));
|
||||
FilterFormat::create(array(
|
||||
$this->installConfig(['filter']);
|
||||
FilterFormat::create([
|
||||
'format' => 'no_filters',
|
||||
'filters' => array(),
|
||||
))->save();
|
||||
'filters' => [],
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,14 +100,14 @@ class TextWithSummaryItemTest extends FieldKernelTestBase {
|
|||
*/
|
||||
protected function createField($entity_type) {
|
||||
// Create a field .
|
||||
$this->fieldStorage = FieldStorageConfig::create(array(
|
||||
$this->fieldStorage = FieldStorageConfig::create([
|
||||
'field_name' => 'summary_field',
|
||||
'entity_type' => $entity_type,
|
||||
'type' => 'text_with_summary',
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'max_length' => 10,
|
||||
)
|
||||
));
|
||||
]
|
||||
]);
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_storage' => $this->fieldStorage,
|
||||
|
|
|
@ -71,12 +71,12 @@ class TextFieldTest extends UnitTestCase {
|
|||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues() {
|
||||
$info = array(
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => array(
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo\nbar",
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
|
@ -96,12 +96,12 @@ class TextFieldTest extends UnitTestCase {
|
|||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues() {
|
||||
$info = array(
|
||||
$info = [
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => array(
|
||||
'global_settings' => [
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
|
@ -121,43 +121,43 @@ class TextFieldTest extends UnitTestCase {
|
|||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return array(
|
||||
array('string_long', 'text_textfield', array(
|
||||
return [
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
)),
|
||||
array('string', 'text_textfield', array(
|
||||
]],
|
||||
['string', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
)),
|
||||
array('string_long', 'text_textfield', array(
|
||||
]],
|
||||
['string_long', 'text_textfield', [
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
)),
|
||||
array('text_long', 'text_textfield', array(
|
||||
]],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
)),
|
||||
array('text', 'text_textfield', array(
|
||||
]],
|
||||
['text', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
)),
|
||||
array('text_long', 'text_textfield', array(
|
||||
]],
|
||||
['text_long', 'text_textfield', [
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
)),
|
||||
array('list_string', 'optionwidgets_buttons'),
|
||||
array('list_string', 'optionwidgets_select'),
|
||||
array('boolean', 'optionwidgets_onoff'),
|
||||
array('text_long', 'text_textarea'),
|
||||
array(NULL, 'undefined'),
|
||||
);
|
||||
]],
|
||||
['list_string', 'optionwidgets_buttons'],
|
||||
['list_string', 'optionwidgets_select'],
|
||||
['boolean', 'optionwidgets_onoff'],
|
||||
['text_long', 'text_textarea'],
|
||||
[NULL, 'undefined'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = array()) {
|
||||
$row = new Row(array('widget_type' => $widget_type), array('widget_type' => array()));
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@ function text_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.text':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Text module allows you to create short and long text fields with optional summaries. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":text_documentation">online documentation for the Text module</a>.', array(':field' => \Drupal::url('help.page', array('name' => 'field')), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#', ':text_documentation' => 'https://www.drupal.org/documentation/modules/text')) . '</p>';
|
||||
$output .= '<p>' . t('The Text module allows you to create short and long text fields with optional summaries. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":text_documentation">online documentation for the Text module</a>.', [':field' => \Drupal::url('help.page', ['name' => 'field']), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#', ':text_documentation' => 'https://www.drupal.org/documentation/modules/text']) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Managing and displaying text fields') . '</dt>';
|
||||
$output .= '<dd>' . t('The <em>settings</em> and <em>display</em> of the text field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', array(':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#')) . '</dd>';
|
||||
$output .= '<dd>' . t('The <em>settings</em> and <em>display</em> of the text field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#']) . '</dd>';
|
||||
$output .= '<dt>' . t('Creating short text fields') . '</dt>';
|
||||
$output .= '<dd>' . t('If you choose <em>Text (plain)</em> or <em>Text (formatted)</em> as the field type on the <em>Manage fields</em> page, then a field with a single row is displayed. You can change the maximum text length in the <em>Field settings</em> when you set up the field.') . '</dd>';
|
||||
$output .= '<dt>' . t('Creating long text fields') . '</dt>';
|
||||
|
@ -32,7 +32,7 @@ function text_help($route_name, RouteMatchInterface $route_match) {
|
|||
$output .= '<dt>' . t('Displaying summaries instead of trimmed text') . '</dt>';
|
||||
$output .= '<dd>' . t('As an alternative to using a trimmed version of the text, you can enter a separate summary by choosing the <em>Text (formatted, long, with summary)</em> field type on the <em>Manage fields</em> page. Even when <em>Summary input</em> is enabled, and summaries are provided, you can display <em>trimmed</em> text nonetheless by choosing the appropriate format on the <em>Manage display</em> page.') . '</dd>';
|
||||
$output .= '<dt>' . t('Using text formats and editors') . '</dt>';
|
||||
$output .= '<dd>' . t('If you choose <em>Text (plain)</em> or <em>Text (plain, long)</em> you restrict the input to <em>Plain text</em> only. If you choose <em>Text (formatted)</em>, <em>Text (formatted, long)</em>, or <em>Text (formatted, long with summary)</em> you allow users to write formatted text. Which options are available to individual users depends on the settings on the <a href=":formats">Text formats and editors page</a>.', array(':formats' => \Drupal::url('filter.admin_overview'))) . '</dd>';
|
||||
$output .= '<dd>' . t('If you choose <em>Text (plain)</em> or <em>Text (plain, long)</em> you restrict the input to <em>Plain text</em> only. If you choose <em>Text (formatted)</em>, <em>Text (formatted, long)</em>, or <em>Text (formatted, long with summary)</em> you allow users to write formatted text. Which options are available to individual users depends on the settings on the <a href=":formats">Text formats and editors page</a>.', [':formats' => \Drupal::url('filter.admin_overview')]) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
}
|
||||
|
@ -115,13 +115,13 @@ function text_summary($text, $format = NULL, $size = NULL) {
|
|||
$reversed = strrev($summary);
|
||||
|
||||
// Build an array of arrays of break points grouped by preference.
|
||||
$break_points = array();
|
||||
$break_points = [];
|
||||
|
||||
// A paragraph near the end of sliced summary is most preferable.
|
||||
$break_points[] = array('</p>' => 0);
|
||||
$break_points[] = ['</p>' => 0];
|
||||
|
||||
// If no complete paragraph then treat line breaks as paragraphs.
|
||||
$line_breaks = array('<br />' => 6, '<br>' => 4);
|
||||
$line_breaks = ['<br />' => 6, '<br>' => 4];
|
||||
// Newline only indicates a line break if line break converter
|
||||
// filter is present.
|
||||
if (isset($format) && $filters->has('filter_autop') && $filters->get('filter_autop')->status) {
|
||||
|
@ -130,7 +130,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
|
|||
$break_points[] = $line_breaks;
|
||||
|
||||
// If the first paragraph is too long, split at the end of a sentence.
|
||||
$break_points[] = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1);
|
||||
$break_points[] = ['. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1];
|
||||
|
||||
// Iterate over the groups of break points until a break point is found.
|
||||
foreach ($break_points as $points) {
|
||||
|
|
Reference in a new issue