Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -81,21 +81,21 @@ function hook_options_list_alter(array &$options, array $context) {
|
|||
*/
|
||||
function callback_allowed_values_function(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = TRUE) {
|
||||
if (isset($entity) && ($entity->bundle() == 'not_a_programmer')) {
|
||||
$values = array(
|
||||
$values = [
|
||||
1 => 'One',
|
||||
2 => 'Two',
|
||||
);
|
||||
];
|
||||
}
|
||||
else {
|
||||
$values = array(
|
||||
'Group 1' => array(
|
||||
$values = [
|
||||
'Group 1' => [
|
||||
0 => 'Zero',
|
||||
1 => 'One',
|
||||
),
|
||||
'Group 2' => array(
|
||||
],
|
||||
'Group 2' => [
|
||||
2 => 'Two',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
|
|
@ -19,11 +19,11 @@ function options_help($route_name, RouteMatchInterface $route_match) {
|
|||
case 'help.page.options':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Options module allows you to create fields where data values are selected from a fixed list of options. Usually these items are entered through a select list, checkboxes, or radio buttons. 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=":options_do">online documentation for the Options 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')) : '#', ':options_do' => 'https://www.drupal.org/documentation/modules/options')) . '</p>';
|
||||
$output .= '<p>' . t('The Options module allows you to create fields where data values are selected from a fixed list of options. Usually these items are entered through a select list, checkboxes, or radio buttons. 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=":options_do">online documentation for the Options module</a>.', [':field' => \Drupal::url('help.page', ['name' => 'field']), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#', ':options_do' => 'https://www.drupal.org/documentation/modules/options']) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Managing and displaying list fields') . '</dt>';
|
||||
$output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the list fields 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 the <em>display</em> of the list fields 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('Defining option keys and labels') . '</dt>';
|
||||
$output .= '<dd>' . t('When you define the list options you can define a key and a label for each option in the list. The label will be shown to the users while the key gets stored in the database.') . '</dd>';
|
||||
$output .= '<dt>' . t('Choosing list field type') . '</dt>';
|
||||
|
@ -70,9 +70,9 @@ function options_field_storage_config_delete(FieldStorageConfigInterface $field_
|
|||
* @see callback_allowed_values_function()
|
||||
*/
|
||||
function options_allowed_values(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) {
|
||||
$allowed_values = &drupal_static(__FUNCTION__, array());
|
||||
$allowed_values = &drupal_static(__FUNCTION__, []);
|
||||
|
||||
$cache_keys = array($definition->getTargetEntityTypeId(), $definition->getName());
|
||||
$cache_keys = [$definition->getTargetEntityTypeId(), $definition->getName()];
|
||||
if ($entity) {
|
||||
$cache_keys[] = 'entity';
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ function options_field_storage_config_update_forbid(FieldStorageConfigInterface
|
|||
$prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
|
||||
$lost_keys = array_keys(array_diff_key($prior_allowed_values, $allowed_values));
|
||||
if (_options_values_in_use($field_storage->getTargetEntityTypeId(), $field_storage->getName(), $lost_keys)) {
|
||||
throw new FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field_storage->getName())));
|
||||
throw new FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', ['@field_name' => $field_storage->getName()]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class OptionsDefaultFormatter extends FormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
// Only collect allowed options if there are actually items to display.
|
||||
if ($items->count()) {
|
||||
|
@ -44,10 +44,10 @@ class OptionsDefaultFormatter extends FormatterBase {
|
|||
// If the stored value is in the current set of allowed values, display
|
||||
// the associated label, otherwise just display the raw value.
|
||||
$output = isset($options[$value]) ? $options[$value] : $value;
|
||||
$elements[$delta] = array(
|
||||
$elements[$delta] = [
|
||||
'#markup' => $output,
|
||||
'#allowed_tags' => FieldFilteredMarkup::allowedTags(),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,13 +28,13 @@ class OptionsKeyFormatter extends FormatterBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
$elements[$delta] = array(
|
||||
$elements[$delta] = [
|
||||
'#markup' => $item->value,
|
||||
'#allowed_tags' => FieldFilteredMarkup::allowedTags(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $elements;
|
||||
|
|
|
@ -34,16 +34,16 @@ class ListFloatItem extends ListItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'value' => array(
|
||||
return [
|
||||
'columns' => [
|
||||
'value' => [
|
||||
'type' => 'float',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'value' => array('value'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'value' => ['value'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ class ListFloatItem extends ListItemBase {
|
|||
$description .= '<br/>' . t('The label is optional: if a line contains a single number, it will be used as key and label.');
|
||||
$description .= '<br/>' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');
|
||||
$description .= '</p>';
|
||||
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', array('@tags' => $this->displayAllowedTags())) . '</p>';
|
||||
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
|
||||
return $description;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ class ListFloatItem extends ListItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function simplifyAllowedValues(array $structured_values) {
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach ($structured_values as $item) {
|
||||
// Nested elements are embedded in the label.
|
||||
if (is_array($item['label'])) {
|
||||
|
|
|
@ -34,16 +34,16 @@ class ListIntegerItem extends ListItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'value' => array(
|
||||
return [
|
||||
'columns' => [
|
||||
'value' => [
|
||||
'type' => 'int',
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'value' => array('value'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'value' => ['value'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ class ListIntegerItem extends ListItemBase {
|
|||
$description .= '<br/>' . t('The label is optional: if a line contains a single number, it will be used as key and label.');
|
||||
$description .= '<br/>' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');
|
||||
$description .= '</p>';
|
||||
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', array('@tags' => $this->displayAllowedTags())) . '</p>';
|
||||
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
|
||||
return $description;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultStorageSettings() {
|
||||
return array(
|
||||
'allowed_values' => array(),
|
||||
return [
|
||||
'allowed_values' => [],
|
||||
'allowed_values_function' => '',
|
||||
) + parent::defaultStorageSettings();
|
||||
] + parent::defaultStorageSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,28 +85,28 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
$allowed_values = $this->getSetting('allowed_values');
|
||||
$allowed_values_function = $this->getSetting('allowed_values_function');
|
||||
|
||||
$element['allowed_values'] = array(
|
||||
$element['allowed_values'] = [
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Allowed values list'),
|
||||
'#default_value' => $this->allowedValuesString($allowed_values),
|
||||
'#rows' => 10,
|
||||
'#access' => empty($allowed_values_function),
|
||||
'#element_validate' => array(array(get_class($this), 'validateAllowedValues')),
|
||||
'#element_validate' => [[get_class($this), 'validateAllowedValues']],
|
||||
'#field_has_data' => $has_data,
|
||||
'#field_name' => $this->getFieldDefinition()->getName(),
|
||||
'#entity_type' => $this->getEntity()->getEntityTypeId(),
|
||||
'#allowed_values' => $allowed_values,
|
||||
);
|
||||
];
|
||||
|
||||
$element['allowed_values']['#description'] = $this->allowedValuesDescription();
|
||||
|
||||
$element['allowed_values_function'] = array(
|
||||
$element['allowed_values_function'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => t('Allowed values list'),
|
||||
'#markup' => t('The value of this field is being determined by the %function function and may not be changed.', array('%function' => $allowed_values_function)),
|
||||
'#markup' => t('The value of this field is being determined by the %function function and may not be changed.', ['%function' => $allowed_values_function]),
|
||||
'#access' => !empty($allowed_values_function),
|
||||
'#value' => $allowed_values_function,
|
||||
);
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
* @see \Drupal\options\Plugin\Field\FieldType\ListItemBase::allowedValuesString()
|
||||
*/
|
||||
protected static function extractAllowedValues($string, $has_data) {
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
$list = explode("\n", $string);
|
||||
$list = array_map('trim', $list);
|
||||
|
@ -180,7 +180,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
$generated_keys = $explicit_keys = FALSE;
|
||||
foreach ($list as $position => $text) {
|
||||
// Check for an explicit key.
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
if (preg_match('/(.*)\|(.*)/', $text, $matches)) {
|
||||
// Trim key and value to avoid unwanted spaces issues.
|
||||
$key = trim($matches[1]);
|
||||
|
@ -239,7 +239,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
* - Each value is in the format "value|label" or "value".
|
||||
*/
|
||||
protected function allowedValuesString($values) {
|
||||
$lines = array();
|
||||
$lines = [];
|
||||
foreach ($values as $key => $value) {
|
||||
$lines[] = "$key|$value";
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
* @see \Drupal\options\Plugin\Field\FieldType\ListItemBase::structureAllowedValues()
|
||||
*/
|
||||
protected static function simplifyAllowedValues(array $structured_values) {
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach ($structured_values as $item) {
|
||||
if (is_array($item['label'])) {
|
||||
// Nested elements are embedded in the label.
|
||||
|
@ -305,15 +305,15 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte
|
|||
* @see \Drupal\options\Plugin\Field\FieldType\ListItemBase::simplifyAllowedValues()
|
||||
*/
|
||||
protected static function structureAllowedValues(array $values) {
|
||||
$structured_values = array();
|
||||
$structured_values = [];
|
||||
foreach ($values as $value => $label) {
|
||||
if (is_array($label)) {
|
||||
$label = static::structureAllowedValues($label);
|
||||
}
|
||||
$structured_values[] = array(
|
||||
$structured_values[] = [
|
||||
'value' => static::castAllowedValue($value),
|
||||
'label' => $label,
|
||||
);
|
||||
];
|
||||
}
|
||||
return $structured_values;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ class ListStringItem extends ListItemBase {
|
|||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
|
||||
$properties['value'] = DataDefinition::create('string')
|
||||
->setLabel(t('Text value'))
|
||||
->addConstraint('Length', array('max' => 255))
|
||||
->addConstraint('Length', ['max' => 255])
|
||||
->setRequired(TRUE);
|
||||
|
||||
return $properties;
|
||||
|
@ -36,17 +36,17 @@ class ListStringItem extends ListItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'value' => array(
|
||||
return [
|
||||
'columns' => [
|
||||
'value' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'value' => array('value'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'value' => ['value'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ class ListStringItem extends ListItemBase {
|
|||
$description .= '<br/>' . t('The key is the stored value. The label will be used in displayed values and edit forms.');
|
||||
$description .= '<br/>' . t('The label is optional: if a line contains a single string, it will be used as key and label.');
|
||||
$description .= '</p>';
|
||||
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', array('@tags' => $this->displayAllowedTags())) . '</p>';
|
||||
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
|
||||
return $description;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ content:
|
|||
title:
|
||||
type: string_textfield
|
||||
weight: -5
|
||||
region: content
|
||||
settings:
|
||||
size: 60
|
||||
placeholder: ''
|
||||
|
@ -21,6 +22,7 @@ content:
|
|||
uid:
|
||||
type: entity_reference_autocomplete
|
||||
weight: 5
|
||||
region: content
|
||||
settings:
|
||||
match_operator: CONTAINS
|
||||
size: 60
|
||||
|
@ -29,6 +31,7 @@ content:
|
|||
created:
|
||||
type: datetime_timestamp
|
||||
weight: 10
|
||||
region: content
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
promote:
|
||||
|
@ -36,16 +39,19 @@ content:
|
|||
settings:
|
||||
display_label: true
|
||||
weight: 15
|
||||
region: content
|
||||
third_party_settings: { }
|
||||
sticky:
|
||||
type: boolean_checkbox
|
||||
settings:
|
||||
display_label: true
|
||||
weight: 16
|
||||
region: content
|
||||
third_party_settings: { }
|
||||
body:
|
||||
type: text_textarea_with_summary
|
||||
weight: 26
|
||||
region: content
|
||||
settings:
|
||||
rows: 9
|
||||
summary_rows: 3
|
||||
|
|
|
@ -14,10 +14,12 @@ mode: default
|
|||
content:
|
||||
links:
|
||||
weight: 100
|
||||
region: content
|
||||
body:
|
||||
label: hidden
|
||||
type: text_default
|
||||
weight: 101
|
||||
region: content
|
||||
settings: { }
|
||||
third_party_settings: { }
|
||||
hidden:
|
||||
|
|
|
@ -15,10 +15,12 @@ mode: teaser
|
|||
content:
|
||||
links:
|
||||
weight: 100
|
||||
region: content
|
||||
body:
|
||||
label: hidden
|
||||
type: text_summary_or_trimmed
|
||||
weight: 101
|
||||
region: content
|
||||
settings:
|
||||
trim_length: 600
|
||||
third_party_settings: { }
|
||||
|
|
|
@ -14,18 +14,18 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
|||
* @see options_allowed_values()
|
||||
*/
|
||||
function options_test_allowed_values_callback(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) {
|
||||
$values = array(
|
||||
'Group 1' => array(
|
||||
$values = [
|
||||
'Group 1' => [
|
||||
0 => 'Zero',
|
||||
),
|
||||
],
|
||||
1 => 'One',
|
||||
'Group 2' => array(
|
||||
'Group 2' => [
|
||||
2 => 'Some <script>dangerous</script> & unescaped <strong>markup</strong>',
|
||||
),
|
||||
'More <script>dangerous</script> markup' => array(
|
||||
],
|
||||
'More <script>dangerous</script> markup' => [
|
||||
3 => 'Three',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
@ -41,15 +41,15 @@ function options_test_allowed_values_callback(FieldStorageDefinitionInterface $d
|
|||
* @see options_allowed_values()
|
||||
*/
|
||||
function options_test_dynamic_values_callback(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable = NULL) {
|
||||
$values = array();
|
||||
$values = [];
|
||||
if (isset($entity)) {
|
||||
$cacheable = FALSE;
|
||||
$values = array(
|
||||
$values = [
|
||||
$entity->label(),
|
||||
$entity->url(),
|
||||
$entity->uuid(),
|
||||
$entity->bundle(),
|
||||
);
|
||||
];
|
||||
}
|
||||
// We need the values of the entity as keys.
|
||||
return array_combine($values, $values);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
/**
|
||||
* Tests the options allowed values api.
|
||||
|
@ -21,12 +21,12 @@ class OptionsDynamicValuesApiTest extends OptionsDynamicValuesTestBase {
|
|||
|
||||
$values = options_allowed_values($this->fieldStorage, $this->entity);
|
||||
|
||||
$expected_values = array(
|
||||
$expected_values = [
|
||||
$this->entity->label(),
|
||||
$this->entity->url(),
|
||||
$this->entity->uuid(),
|
||||
$this->entity->bundle(),
|
||||
);
|
||||
];
|
||||
$expected_values = array_combine($expected_values, $expected_values);
|
||||
$this->assertEqual($expected_values, $values);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Tests\FieldTestBase;
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
/**
|
||||
* Tests the Options field allowed values function.
|
||||
|
@ -11,7 +11,7 @@ class OptionsDynamicValuesValidationTest extends OptionsDynamicValuesTestBase {
|
|||
/**
|
||||
* Test that allowed values function gets the entity.
|
||||
*/
|
||||
function testDynamicAllowedValues() {
|
||||
public function testDynamicAllowedValues() {
|
||||
// Verify that validation passes against every value we had.
|
||||
foreach ($this->test as $key => $value) {
|
||||
$this->entity->test_options->value = $value;
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
@ -18,7 +18,7 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'options', 'field_test', 'taxonomy', 'field_ui');
|
||||
public static $modules = ['node', 'options', 'field_test', 'taxonomy', 'field_ui'];
|
||||
|
||||
/**
|
||||
* The name of the created content type.
|
||||
|
@ -64,21 +64,21 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
/**
|
||||
* Options (integer) : test 'allowed values' input.
|
||||
*/
|
||||
function testOptionsAllowedValuesInteger() {
|
||||
public function testOptionsAllowedValuesInteger() {
|
||||
$this->fieldName = 'field_options_integer';
|
||||
$this->createOptionsField('list_integer');
|
||||
|
||||
// Flat list of textual values.
|
||||
$string = "Zero\nOne";
|
||||
$array = array('0' => 'Zero', '1' => 'One');
|
||||
$array = ['0' => 'Zero', '1' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are accepted.');
|
||||
// Explicit integer keys.
|
||||
$string = "0|Zero\n2|Two";
|
||||
$array = array('0' => 'Zero', '2' => 'Two');
|
||||
$array = ['0' => 'Zero', '2' => 'Two'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Integer keys are accepted.');
|
||||
// Check that values can be added and removed.
|
||||
$string = "0|Zero\n1|One";
|
||||
$array = array('0' => 'Zero', '1' => 'One');
|
||||
$array = ['0' => 'Zero', '1' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values can be added and removed.');
|
||||
// Non-integer keys.
|
||||
$this->assertAllowedValuesInput("1.1|One", 'keys must be integers', 'Non integer keys are rejected.');
|
||||
|
@ -87,10 +87,10 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
$this->assertAllowedValuesInput("Zero\n1|One", 'invalid input', 'Mixed lists are rejected.');
|
||||
|
||||
// Create a node with actual data for the field.
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => $this->type,
|
||||
$this->fieldName => array(array('value' => 1)),
|
||||
);
|
||||
$this->fieldName => [['value' => 1]],
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Check that a flat list of values is rejected once the field has data.
|
||||
|
@ -98,43 +98,43 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
|
||||
// Check that values can be added but values in use cannot be removed.
|
||||
$string = "0|Zero\n1|One\n2|Two";
|
||||
$array = array('0' => 'Zero', '1' => 'One', '2' => 'Two');
|
||||
$array = ['0' => 'Zero', '1' => 'One', '2' => 'Two'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values can be added.');
|
||||
$string = "0|Zero\n1|One";
|
||||
$array = array('0' => 'Zero', '1' => 'One');
|
||||
$array = ['0' => 'Zero', '1' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.');
|
||||
$this->assertAllowedValuesInput("0|Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.');
|
||||
|
||||
// Delete the node, remove the value.
|
||||
$node->delete();
|
||||
$string = "0|Zero";
|
||||
$array = array('0' => 'Zero');
|
||||
$array = ['0' => 'Zero'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.');
|
||||
|
||||
// Check that the same key can only be used once.
|
||||
$string = "0|Zero\n0|One";
|
||||
$array = array('0' => 'One');
|
||||
$array = ['0' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Same value cannot be used multiple times.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Options (float) : test 'allowed values' input.
|
||||
*/
|
||||
function testOptionsAllowedValuesFloat() {
|
||||
public function testOptionsAllowedValuesFloat() {
|
||||
$this->fieldName = 'field_options_float';
|
||||
$this->createOptionsField('list_float');
|
||||
|
||||
// Flat list of textual values.
|
||||
$string = "Zero\nOne";
|
||||
$array = array('0' => 'Zero', '1' => 'One');
|
||||
$array = ['0' => 'Zero', '1' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are accepted.');
|
||||
// Explicit numeric keys.
|
||||
$string = "0|Zero\n.5|Point five";
|
||||
$array = array('0' => 'Zero', '0.5' => 'Point five');
|
||||
$array = ['0' => 'Zero', '0.5' => 'Point five'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Integer keys are accepted.');
|
||||
// Check that values can be added and removed.
|
||||
$string = "0|Zero\n.5|Point five\n1.0|One";
|
||||
$array = array('0' => 'Zero', '0.5' => 'Point five', '1' => 'One');
|
||||
$array = ['0' => 'Zero', '0.5' => 'Point five', '1' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values can be added and removed.');
|
||||
// Non-numeric keys.
|
||||
$this->assertAllowedValuesInput("abc|abc\n", 'each key must be a valid integer or decimal', 'Non numeric keys are rejected.');
|
||||
|
@ -142,10 +142,10 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
$this->assertAllowedValuesInput("Zero\n1|One\n", 'invalid input', 'Mixed lists are rejected.');
|
||||
|
||||
// Create a node with actual data for the field.
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => $this->type,
|
||||
$this->fieldName => array(array('value' => .5)),
|
||||
);
|
||||
$this->fieldName => [['value' => .5]],
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Check that a flat list of values is rejected once the field has data.
|
||||
|
@ -153,105 +153,105 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
|
||||
// Check that values can be added but values in use cannot be removed.
|
||||
$string = "0|Zero\n.5|Point five\n2|Two";
|
||||
$array = array('0' => 'Zero', '0.5' => 'Point five', '2' => 'Two');
|
||||
$array = ['0' => 'Zero', '0.5' => 'Point five', '2' => 'Two'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values can be added.');
|
||||
$string = "0|Zero\n.5|Point five";
|
||||
$array = array('0' => 'Zero', '0.5' => 'Point five');
|
||||
$array = ['0' => 'Zero', '0.5' => 'Point five'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.');
|
||||
$this->assertAllowedValuesInput("0|Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.');
|
||||
|
||||
// Delete the node, remove the value.
|
||||
$node->delete();
|
||||
$string = "0|Zero";
|
||||
$array = array('0' => 'Zero');
|
||||
$array = ['0' => 'Zero'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.');
|
||||
|
||||
// Check that the same key can only be used once.
|
||||
$string = "0.5|Point five\n0.5|Half";
|
||||
$array = array('0.5' => 'Half');
|
||||
$array = ['0.5' => 'Half'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Same value cannot be used multiple times.');
|
||||
|
||||
// Check that different forms of the same float value cannot be used.
|
||||
$string = "0|Zero\n.5|Point five\n0.5|Half";
|
||||
$array = array('0' => 'Zero', '0.5' => 'Half');
|
||||
$array = ['0' => 'Zero', '0.5' => 'Half'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Different forms of the same value cannot be used.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Options (text) : test 'allowed values' input.
|
||||
*/
|
||||
function testOptionsAllowedValuesText() {
|
||||
public function testOptionsAllowedValuesText() {
|
||||
$this->fieldName = 'field_options_text';
|
||||
$this->createOptionsField('list_string');
|
||||
|
||||
// Flat list of textual values.
|
||||
$string = "Zero\nOne";
|
||||
$array = array('Zero' => 'Zero', 'One' => 'One');
|
||||
$array = ['Zero' => 'Zero', 'One' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are accepted.');
|
||||
// Explicit keys.
|
||||
$string = "zero|Zero\none|One";
|
||||
$array = array('zero' => 'Zero', 'one' => 'One');
|
||||
$array = ['zero' => 'Zero', 'one' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Explicit keys are accepted.');
|
||||
// Check that values can be added and removed.
|
||||
$string = "zero|Zero\ntwo|Two";
|
||||
$array = array('zero' => 'Zero', 'two' => 'Two');
|
||||
$array = ['zero' => 'Zero', 'two' => 'Two'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values can be added and removed.');
|
||||
// Mixed list of keyed and unkeyed values.
|
||||
$string = "zero|Zero\nOne\n";
|
||||
$array = array('zero' => 'Zero', 'One' => 'One');
|
||||
$array = ['zero' => 'Zero', 'One' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Mixed lists are accepted.');
|
||||
// Overly long keys.
|
||||
$this->assertAllowedValuesInput("zero|Zero\n" . $this->randomMachineName(256) . "|One", 'each key must be a string at most 255 characters long', 'Overly long keys are rejected.');
|
||||
|
||||
// Create a node with actual data for the field.
|
||||
$settings = array(
|
||||
$settings = [
|
||||
'type' => $this->type,
|
||||
$this->fieldName => array(array('value' => 'One')),
|
||||
);
|
||||
$this->fieldName => [['value' => 'One']],
|
||||
];
|
||||
$node = $this->drupalCreateNode($settings);
|
||||
|
||||
// Check that flat lists of values are still accepted once the field has
|
||||
// data.
|
||||
$string = "Zero\nOne";
|
||||
$array = array('Zero' => 'Zero', 'One' => 'One');
|
||||
$array = ['Zero' => 'Zero', 'One' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Unkeyed lists are still accepted once the field has data.');
|
||||
|
||||
// Check that values can be added but values in use cannot be removed.
|
||||
$string = "Zero\nOne\nTwo";
|
||||
$array = array('Zero' => 'Zero', 'One' => 'One', 'Two' => 'Two');
|
||||
$array = ['Zero' => 'Zero', 'One' => 'One', 'Two' => 'Two'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values can be added.');
|
||||
$string = "Zero\nOne";
|
||||
$array = array('Zero' => 'Zero', 'One' => 'One');
|
||||
$array = ['Zero' => 'Zero', 'One' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.');
|
||||
$this->assertAllowedValuesInput("Zero", 'some values are being removed while currently in use', 'Values in use cannot be removed.');
|
||||
|
||||
// Delete the node, remove the value.
|
||||
$node->delete();
|
||||
$string = "Zero";
|
||||
$array = array('Zero' => 'Zero');
|
||||
$array = ['Zero' => 'Zero'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Values not in use can be removed.');
|
||||
|
||||
// Check that string values with dots can be used.
|
||||
$string = "Zero\nexample.com|Example";
|
||||
$array = array('Zero' => 'Zero', 'example.com' => 'Example');
|
||||
$array = ['Zero' => 'Zero', 'example.com' => 'Example'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'String value with dot is supported.');
|
||||
|
||||
// Check that the same key can only be used once.
|
||||
$string = "zero|Zero\nzero|One";
|
||||
$array = array('zero' => 'One');
|
||||
$array = ['zero' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Same value cannot be used multiple times.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Options (text) : test 'trimmed values' input.
|
||||
*/
|
||||
function testOptionsTrimmedValuesText() {
|
||||
public function testOptionsTrimmedValuesText() {
|
||||
$this->fieldName = 'field_options_trimmed_text';
|
||||
$this->createOptionsField('list_string');
|
||||
|
||||
// Explicit keys.
|
||||
$string = "zero |Zero\none | One";
|
||||
$array = array('zero' => 'Zero', 'one' => 'One');
|
||||
$array = ['zero' => 'Zero', 'one' => 'One'];
|
||||
$this->assertAllowedValuesInput($string, $array, 'Explicit keys are accepted and trimmed.');
|
||||
}
|
||||
|
||||
|
@ -263,11 +263,11 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
*/
|
||||
protected function createOptionsField($type) {
|
||||
// Create a field.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'node',
|
||||
'type' => $type,
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'node',
|
||||
|
@ -291,8 +291,8 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
* @param $message
|
||||
* Message to display.
|
||||
*/
|
||||
function assertAllowedValuesInput($input_string, $result, $message) {
|
||||
$edit = array('settings[allowed_values]' => $input_string);
|
||||
public function assertAllowedValuesInput($input_string, $result, $message) {
|
||||
$edit = ['settings[allowed_values]' => $input_string];
|
||||
$this->drupalPostForm($this->adminPath, $edit, t('Save field settings'));
|
||||
$this->assertNoRaw('&lt;', 'The page does not have double escaped HTML tags.');
|
||||
|
||||
|
@ -308,34 +308,35 @@ class OptionsFieldUITest extends FieldTestBase {
|
|||
/**
|
||||
* Tests normal and key formatter display on node display.
|
||||
*/
|
||||
function testNodeDisplay() {
|
||||
public function testNodeDisplay() {
|
||||
$this->fieldName = strtolower($this->randomMachineName());
|
||||
$this->createOptionsField('list_integer');
|
||||
$node = $this->drupalCreateNode(array('type' => $this->type));
|
||||
$node = $this->drupalCreateNode(['type' => $this->type]);
|
||||
|
||||
$on = $this->randomMachineName();
|
||||
$off = $this->randomMachineName();
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'settings[allowed_values]' =>
|
||||
"1|$on
|
||||
0|$off",
|
||||
);
|
||||
];
|
||||
|
||||
$this->drupalPostForm($this->adminPath, $edit, t('Save field settings'));
|
||||
$this->assertText(format_string('Updated field @field_name field settings.', array('@field_name' => $this->fieldName)), "The 'On' and 'Off' form fields work for boolean fields.");
|
||||
$this->assertText(format_string('Updated field @field_name field settings.', ['@field_name' => $this->fieldName]), "The 'On' and 'Off' form fields work for boolean fields.");
|
||||
|
||||
// Select a default value.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
$this->fieldName => '1',
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
|
||||
|
||||
// Check the node page and see if the values are correct.
|
||||
$file_formatters = array('list_default', 'list_key');
|
||||
$file_formatters = ['list_default', 'list_key'];
|
||||
foreach ($file_formatters as $formatter) {
|
||||
$edit = array(
|
||||
$edit = [
|
||||
"fields[$this->fieldName][type]" => $formatter,
|
||||
);
|
||||
"fields[$this->fieldName][region]" => 'content',
|
||||
];
|
||||
$this->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/display', $edit, t('Save'));
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
@ -18,13 +18,13 @@ class OptionsFloatFieldImportTest extends FieldTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'options', 'field_ui', 'config', 'options_config_install_test');
|
||||
public static $modules = ['node', 'options', 'field_ui', 'config', 'options_config_install_test'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create test user.
|
||||
$admin_user = $this->drupalCreateUser(array('synchronize configuration', 'access content', 'access administration pages', 'administer site configuration', 'administer content types', 'administer nodes', 'bypass node access', 'administer node fields', 'administer node display'));
|
||||
$admin_user = $this->drupalCreateUser(['synchronize configuration', 'access content', 'access administration pages', 'administer site configuration', 'administer content types', 'administer nodes', 'bypass node access', 'administer node fields', 'administer node display']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ class OptionsFloatFieldImportTest extends FieldTestBase {
|
|||
// necessary configuration for this test is created by installing that
|
||||
// module.
|
||||
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);
|
||||
|
||||
$admin_path = 'admin/structure/types/manage/' . $type . '/fields/node.' . $type . '.' . $field_name . '/storage';
|
||||
|
||||
|
@ -47,26 +47,26 @@ class OptionsFloatFieldImportTest extends FieldTestBase {
|
|||
$this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.sync'));
|
||||
|
||||
// Set the active to not use dots in the allowed values key names.
|
||||
$edit = array('settings[allowed_values]' => "0|Zero\n1|One");
|
||||
$edit = ['settings[allowed_values]' => "0|Zero\n1|One"];
|
||||
$this->drupalPostForm($admin_path, $edit, t('Save field settings'));
|
||||
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '1' => 'One'));
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '1' => 'One']);
|
||||
|
||||
// Import configuration with dots in the allowed values key names. This
|
||||
// tests \Drupal\Core\Config\Entity\ConfigEntityStorage::importUpdate().
|
||||
$this->drupalGet('admin/config/development/configuration');
|
||||
$this->drupalPostForm(NULL, array(), t('Import all'));
|
||||
$this->drupalPostForm(NULL, [], t('Import all'));
|
||||
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);
|
||||
|
||||
// Delete field to test creation. This tests
|
||||
// \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate().
|
||||
FieldConfig::loadByName('node', $type, $field_name)->delete();
|
||||
|
||||
$this->drupalGet('admin/config/development/configuration');
|
||||
$this->drupalPostForm(NULL, array(), t('Import all'));
|
||||
$this->drupalPostForm(NULL, [], t('Import all'));
|
||||
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '0.5' => 'Point five'));
|
||||
$this->assertIdentical($field_storage->getSetting('allowed_values'), $array = ['0' => 'Zero', '0.5' => 'Point five']);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
/**
|
||||
* Tests an options select with a dynamic allowed values function.
|
||||
|
@ -11,12 +11,12 @@ class OptionsSelectDynamicValuesTest extends OptionsDynamicValuesTestBase {
|
|||
/**
|
||||
* Tests the 'options_select' widget (single select).
|
||||
*/
|
||||
function testSelectListDynamic() {
|
||||
public function testSelectListDynamic() {
|
||||
// Create an entity.
|
||||
$this->entity->save();
|
||||
|
||||
// Create a web user.
|
||||
$web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content'));
|
||||
$web_user = $this->drupalCreateUser(['view test entity', 'administer entity_test content']);
|
||||
$this->drupalLogin($web_user);
|
||||
|
||||
// Display form.
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\options\Tests;
|
||||
namespace Drupal\Tests\options\Functional;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
|
@ -84,7 +84,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
/**
|
||||
* Tests the 'options_buttons' widget (single select).
|
||||
*/
|
||||
function testRadioButtons() {
|
||||
public function testRadioButtons() {
|
||||
// Create an instance of the 'single value' field.
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card1,
|
||||
|
@ -114,9 +114,9 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertRaw('Some HTML encoded markup with < & >');
|
||||
|
||||
// Select first option.
|
||||
$edit = array('card_1' => 0);
|
||||
$edit = ['card_1' => 0];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_1', [0]);
|
||||
|
||||
// Check that the selected button is checked.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -125,9 +125,9 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertNoFieldChecked('edit-card-1-2');
|
||||
|
||||
// Unselect option.
|
||||
$edit = array('card_1' => '_none');
|
||||
$edit = ['card_1' => '_none'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array());
|
||||
$this->assertFieldValues($entity_init, 'card_1', []);
|
||||
|
||||
// Check that required radios with one option is auto-selected.
|
||||
$this->card1->setSetting('allowed_values', [99 => 'Only allowed value']);
|
||||
|
@ -141,7 +141,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
/**
|
||||
* Tests the 'options_buttons' widget (multiple select).
|
||||
*/
|
||||
function testCheckBoxes() {
|
||||
public function testCheckBoxes() {
|
||||
// Create an instance of the 'multiple values' field.
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card2,
|
||||
|
@ -149,16 +149,16 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card2->getName(), array(
|
||||
->setComponent($this->card2->getName(), [
|
||||
'type' => 'options_buttons',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = EntityTest::create(array(
|
||||
$entity = EntityTest::create([
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
]);
|
||||
$entity->save();
|
||||
$entity_init = clone $entity;
|
||||
|
||||
|
@ -170,13 +170,13 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertRaw('Some dangerous & unescaped <strong>markup</strong>', 'Option text was properly filtered.');
|
||||
|
||||
// Submit form: select first and third options.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'card_2[0]' => TRUE,
|
||||
'card_2[1]' => FALSE,
|
||||
'card_2[2]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array(0, 2));
|
||||
$this->assertFieldValues($entity_init, 'card_2', [0, 2]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -185,13 +185,13 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertFieldChecked('edit-card-2-2');
|
||||
|
||||
// Submit form: select only first option.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'card_2[0]' => TRUE,
|
||||
'card_2[1]' => FALSE,
|
||||
'card_2[2]' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_2', [0]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -200,23 +200,23 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertNoFieldChecked('edit-card-2-2');
|
||||
|
||||
// Submit form: select the three options while the field accepts only 2.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'card_2[0]' => TRUE,
|
||||
'card_2[1]' => TRUE,
|
||||
'card_2[2]' => TRUE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertText('this field cannot hold more than 2 values', 'Validation error was displayed.');
|
||||
|
||||
// Submit form: uncheck all options.
|
||||
$edit = array(
|
||||
$edit = [
|
||||
'card_2[0]' => FALSE,
|
||||
'card_2[1]' => FALSE,
|
||||
'card_2[2]' => FALSE,
|
||||
);
|
||||
];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
// Check that the value was saved.
|
||||
$this->assertFieldValues($entity_init, 'card_2', array());
|
||||
$this->assertFieldValues($entity_init, 'card_2', []);
|
||||
|
||||
// Required checkbox with one option is auto-selected.
|
||||
$this->card2->setSetting('allowed_values', [99 => 'Only allowed value']);
|
||||
|
@ -230,7 +230,7 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
/**
|
||||
* Tests the 'options_select' widget (single select).
|
||||
*/
|
||||
function testSelectListSingle() {
|
||||
public function testSelectListSingle() {
|
||||
// Create an instance of the 'single value' field.
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card1,
|
||||
|
@ -239,23 +239,23 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card1->getName(), array(
|
||||
->setComponent($this->card1->getName(), [
|
||||
'type' => 'options_select',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = EntityTest::create(array(
|
||||
$entity = EntityTest::create([
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
]);
|
||||
$entity->save();
|
||||
$entity_init = clone $entity;
|
||||
|
||||
// Display form.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
// A required field without any value has a "none" option.
|
||||
$this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1', ':label' => t('- Select a value -'))), 'A required select list has a "Select a value" choice.');
|
||||
$this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => t('- Select a value -')]), 'A required select list has a "Select a value" choice.');
|
||||
|
||||
// With no field data, nothing is selected.
|
||||
$this->assertNoOptionSelected('edit-card-1', '_none');
|
||||
|
@ -265,19 +265,19 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
|
||||
|
||||
// Submit form: select invalid 'none' option.
|
||||
$edit = array('card_1' => '_none');
|
||||
$edit = ['card_1' => '_none'];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertRaw(t('@title field is required.', array('@title' => $field->getName())), 'Cannot save a required field when selecting "none" from the select list.');
|
||||
$this->assertRaw(t('@title field is required.', ['@title' => $field->getName()]), 'Cannot save a required field when selecting "none" from the select list.');
|
||||
|
||||
// Submit form: select first option.
|
||||
$edit = array('card_1' => 0);
|
||||
$edit = ['card_1' => 0];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_1', [0]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
// A required field with a value has no 'none' option.
|
||||
$this->assertFalse($this->xpath('//select[@id=:id]//option[@value="_none"]', array(':id' => 'edit-card-1')), 'A required select list with an actual value has no "none" choice.');
|
||||
$this->assertFalse($this->xpath('//select[@id=:id]//option[@value="_none"]', [':id' => 'edit-card-1']), 'A required select list with an actual value has no "none" choice.');
|
||||
$this->assertOptionSelected('edit-card-1', 0);
|
||||
$this->assertNoOptionSelected('edit-card-1', 1);
|
||||
$this->assertNoOptionSelected('edit-card-1', 2);
|
||||
|
@ -289,11 +289,11 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
// Display form.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
// A non-required field has a 'none' option.
|
||||
$this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1', ':label' => t('- None -'))), 'A non-required select list has a "None" choice.');
|
||||
$this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => t('- None -')]), 'A non-required select list has a "None" choice.');
|
||||
// Submit form: Unselect the option.
|
||||
$edit = array('card_1' => '_none');
|
||||
$edit = ['card_1' => '_none'];
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array());
|
||||
$this->assertFieldValues($entity_init, 'card_1', []);
|
||||
|
||||
// Test optgroups.
|
||||
|
||||
|
@ -311,9 +311,9 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertRaw('Group 1', 'Option groups are displayed.');
|
||||
|
||||
// Submit form: select first option.
|
||||
$edit = array('card_1' => 0);
|
||||
$edit = ['card_1' => 0];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_1', [0]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -322,15 +322,15 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertNoOptionSelected('edit-card-1', 2);
|
||||
|
||||
// Submit form: Unselect the option.
|
||||
$edit = array('card_1' => '_none');
|
||||
$edit = ['card_1' => '_none'];
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_1', array());
|
||||
$this->assertFieldValues($entity_init, 'card_1', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the 'options_select' widget (multiple select).
|
||||
*/
|
||||
function testSelectListMultiple() {
|
||||
public function testSelectListMultiple() {
|
||||
// Create an instance of the 'multiple values' field.
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card2,
|
||||
|
@ -338,16 +338,16 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
]);
|
||||
$field->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card2->getName(), array(
|
||||
->setComponent($this->card2->getName(), [
|
||||
'type' => 'options_select',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Create an entity.
|
||||
$entity = EntityTest::create(array(
|
||||
$entity = EntityTest::create([
|
||||
'user_id' => 1,
|
||||
'name' => $this->randomMachineName(),
|
||||
));
|
||||
]);
|
||||
$entity->save();
|
||||
$entity_init = clone $entity;
|
||||
|
||||
|
@ -360,9 +360,9 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
|
||||
|
||||
// Submit form: select first and third options.
|
||||
$edit = array('card_2[]' => array(0 => 0, 2 => 2));
|
||||
$edit = ['card_2[]' => [0 => 0, 2 => 2]];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array(0, 2));
|
||||
$this->assertFieldValues($entity_init, 'card_2', [0, 2]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -371,9 +371,9 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertOptionSelected('edit-card-2', 2);
|
||||
|
||||
// Submit form: select only first option.
|
||||
$edit = array('card_2[]' => array(0 => 0));
|
||||
$edit = ['card_2[]' => [0 => 0]];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_2', [0]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -382,33 +382,33 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertNoOptionSelected('edit-card-2', 2);
|
||||
|
||||
// Submit form: select the three options while the field accepts only 2.
|
||||
$edit = array('card_2[]' => array(0 => 0, 1 => 1, 2 => 2));
|
||||
$edit = ['card_2[]' => [0 => 0, 1 => 1, 2 => 2]];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertText('this field cannot hold more than 2 values', 'Validation error was displayed.');
|
||||
|
||||
// Submit form: uncheck all options.
|
||||
$edit = array('card_2[]' => array());
|
||||
$edit = ['card_2[]' => []];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array());
|
||||
$this->assertFieldValues($entity_init, 'card_2', []);
|
||||
|
||||
// Test the 'None' option.
|
||||
|
||||
// Check that the 'none' option has no effect if actual options are selected
|
||||
// as well.
|
||||
$edit = array('card_2[]' => array('_none' => '_none', 0 => 0));
|
||||
$edit = ['card_2[]' => ['_none' => '_none', 0 => 0]];
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_2', [0]);
|
||||
|
||||
// Check that selecting the 'none' option empties the field.
|
||||
$edit = array('card_2[]' => array('_none' => '_none'));
|
||||
$edit = ['card_2[]' => ['_none' => '_none']];
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array());
|
||||
$this->assertFieldValues($entity_init, 'card_2', []);
|
||||
|
||||
// A required select list does not have an empty key.
|
||||
$field->setRequired(TRUE);
|
||||
$field->save();
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
$this->assertFalse($this->xpath('//select[@id=:id]//option[@value=""]', array(':id' => 'edit-card-2')), 'A required select list does not have an empty key.');
|
||||
$this->assertFalse($this->xpath('//select[@id=:id]//option[@value=""]', [':id' => 'edit-card-2']), 'A required select list does not have an empty key.');
|
||||
|
||||
// We do not have to test that a required select list with one option is
|
||||
// auto-selected because the browser does it for us.
|
||||
|
@ -432,9 +432,9 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertRaw('Group 1', 'Option groups are displayed.');
|
||||
|
||||
// Submit form: select first option.
|
||||
$edit = array('card_2[]' => array(0 => 0));
|
||||
$edit = ['card_2[]' => [0 => 0]];
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array(0));
|
||||
$this->assertFieldValues($entity_init, 'card_2', [0]);
|
||||
|
||||
// Display form: check that the right options are selected.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
|
@ -443,15 +443,15 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
$this->assertNoOptionSelected('edit-card-2', 2);
|
||||
|
||||
// Submit form: Unselect the option.
|
||||
$edit = array('card_2[]' => array('_none' => '_none'));
|
||||
$edit = ['card_2[]' => ['_none' => '_none']];
|
||||
$this->drupalPostForm('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
|
||||
$this->assertFieldValues($entity_init, 'card_2', array());
|
||||
$this->assertFieldValues($entity_init, 'card_2', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the 'options_select' and 'options_button' widget for empty value.
|
||||
*/
|
||||
function testEmptyValue() {
|
||||
public function testEmptyValue() {
|
||||
// Create an instance of the 'single value' field.
|
||||
$field = FieldConfig::create([
|
||||
'field_storage' => $this->card1,
|
||||
|
@ -475,20 +475,20 @@ class OptionsWidgetsTest extends FieldTestBase {
|
|||
|
||||
// Display form: check that _none options are present and has label.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
$this->assertTrue($this->xpath('//div[@id=:id]//input[@value=:value]', array(':id' => 'edit-card-1', ':value' => '_none')), 'A test radio button has a "None" choice.');
|
||||
$this->assertTrue($this->xpath('//div[@id=:id]//label[@for=:for and text()=:label]', array(':id' => 'edit-card-1', ':for' => 'edit-card-1-none', ':label' => 'N/A')), 'A test radio button has a "N/A" choice.');
|
||||
$this->assertTrue($this->xpath('//div[@id=:id]//input[@value=:value]', [':id' => 'edit-card-1', ':value' => '_none']), 'A test radio button has a "None" choice.');
|
||||
$this->assertTrue($this->xpath('//div[@id=:id]//label[@for=:for and text()=:label]', [':id' => 'edit-card-1', ':for' => 'edit-card-1-none', ':label' => 'N/A']), 'A test radio button has a "N/A" choice.');
|
||||
|
||||
// Change it to the select widget.
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->card1->getName(), array(
|
||||
->setComponent($this->card1->getName(), [
|
||||
'type' => 'options_select',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
|
||||
// Display form: check that _none options are present and has label.
|
||||
$this->drupalGet('entity_test/manage/' . $entity->id() . '/edit');
|
||||
// A required field without any value has a "none" option.
|
||||
$this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1', ':label' => t('- None -'))), 'A test select has a "None" choice.');
|
||||
$this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', [':id' => 'edit-card-1', ':label' => t('- None -')]), 'A test select has a "None" choice.');
|
||||
}
|
||||
|
||||
}
|
|
@ -19,12 +19,12 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('options');
|
||||
public static $modules = ['options'];
|
||||
|
||||
/**
|
||||
* Test that allowed values can be updated.
|
||||
*/
|
||||
function testUpdateAllowedValues() {
|
||||
public function testUpdateAllowedValues() {
|
||||
// All three options appear.
|
||||
$entity = EntityTest::create();
|
||||
$form = \Drupal::service('entity.form_builder')->getForm($entity);
|
||||
|
@ -81,9 +81,9 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
|
|||
'required' => TRUE,
|
||||
])->save();
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->fieldName, array(
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'options_buttons',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
$entity = EntityTest::create();
|
||||
$form = \Drupal::service('entity.form_builder')->getForm($entity);
|
||||
|
|
|
@ -16,7 +16,7 @@ abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('options');
|
||||
public static $modules = ['options'];
|
||||
|
||||
/**
|
||||
* The field name used in the test.
|
||||
|
@ -53,15 +53,15 @@ abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase {
|
|||
parent::setUp();
|
||||
$this->container->get('router.builder')->rebuild();
|
||||
|
||||
$this->fieldStorageDefinition = array(
|
||||
$this->fieldStorageDefinition = [
|
||||
'field_name' => $this->fieldName,
|
||||
'entity_type' => 'entity_test',
|
||||
'type' => 'list_integer',
|
||||
'cardinality' => 1,
|
||||
'settings' => array(
|
||||
'allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'),
|
||||
),
|
||||
);
|
||||
'settings' => [
|
||||
'allowed_values' => [1 => 'One', 2 => 'Two', 3 => 'Three'],
|
||||
],
|
||||
];
|
||||
$this->fieldStorage = FieldStorageConfig::create($this->fieldStorageDefinition);
|
||||
$this->fieldStorage->save();
|
||||
|
||||
|
@ -72,9 +72,9 @@ abstract class OptionsFieldUnitTestBase extends FieldKernelTestBase {
|
|||
$this->field->save();
|
||||
|
||||
entity_get_form_display('entity_test', 'entity_test', 'default')
|
||||
->setComponent($this->fieldName, array(
|
||||
->setComponent($this->fieldName, [
|
||||
'type' => 'options_buttons',
|
||||
))
|
||||
])
|
||||
->save();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class OptionsFormattersTest extends OptionsFieldUnitTestBase {
|
|||
$this->assertEqual($build['#formatter'], 'list_default', 'Ensure to fall back to the default formatter.');
|
||||
$this->assertEqual($build[0]['#markup'], 'One');
|
||||
|
||||
$build = $items->view(array('type' => 'list_key'));
|
||||
$build = $items->view(['type' => 'list_key']);
|
||||
$this->assertEqual($build['#formatter'], 'list_key', 'The chosen formatter is used.');
|
||||
$this->assertEqual((string) $build[0]['#markup'], 1);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class FileViewsDataTest extends ViewsKernelTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('file', 'views', 'entity_test', 'user', 'field');
|
||||
public static $modules = ['file', 'views', 'entity_test', 'user', 'field'];
|
||||
|
||||
/**
|
||||
* Tests views data generated for file field relationship.
|
||||
|
@ -29,16 +29,16 @@ class FileViewsDataTest extends ViewsKernelTestBase {
|
|||
*/
|
||||
public function testRelationshipViewsData() {
|
||||
// Create file field to entity_test.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_base_file',
|
||||
'type' => 'file',
|
||||
))->save();
|
||||
FieldConfig::create(array(
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test',
|
||||
'field_name' => 'field_base_file',
|
||||
'bundle' => 'entity_test',
|
||||
))->save();
|
||||
])->save();
|
||||
// Check the generated views data.
|
||||
$views_data = Views::viewsData()->get('entity_test__field_base_file');
|
||||
$relationship = $views_data['field_base_file_target_id']['relationship'];
|
||||
|
@ -59,16 +59,16 @@ class FileViewsDataTest extends ViewsKernelTestBase {
|
|||
$this->assertEqual($relationship['join_extra'][0], ['field' => 'deleted', 'value' => 0, 'numeric' => TRUE]);
|
||||
|
||||
// Create file field to entity_test_mul.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => 'entity_test_mul',
|
||||
'field_name' => 'field_data_file',
|
||||
'type' => 'file',
|
||||
))->save();
|
||||
FieldConfig::create(array(
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => 'entity_test_mul',
|
||||
'field_name' => 'field_data_file',
|
||||
'bundle' => 'entity_test_mul',
|
||||
))->save();
|
||||
])->save();
|
||||
// Check the generated views data.
|
||||
$views_data = Views::viewsData()->get('entity_test_mul__field_data_file');
|
||||
$relationship = $views_data['field_data_file_target_id']['relationship'];
|
||||
|
|
|
@ -35,4 +35,78 @@ class OptionsListFilterTest extends OptionsTestBase {
|
|||
$this->assertIdenticalResultset($view, $resultset, $column_map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests options list field filter when grouped.
|
||||
*/
|
||||
public function testViewsTestOptionsListGroupedFilter() {
|
||||
$view = Views::getView('test_options_list_filter');
|
||||
|
||||
$filters = [
|
||||
'field_test_list_string_value' => [
|
||||
'id' => 'field_test_list_string_value',
|
||||
'table' => 'field_data_field_test_list_string',
|
||||
'field' => 'field_test_list_string_value',
|
||||
'relationship' => 'none',
|
||||
'group_type' => 'group',
|
||||
'admin_label' => '',
|
||||
'operator' => 'or',
|
||||
'value' => [
|
||||
'man' => 'man',
|
||||
'woman' => 'woman',
|
||||
],
|
||||
'group' => '1',
|
||||
'exposed' => TRUE,
|
||||
'expose' => [
|
||||
'operator_id' => 'field_test_list_string_value_op',
|
||||
'label' => 'list-text',
|
||||
'description' => '',
|
||||
'identifier' => 'field_test_list_string_value',
|
||||
],
|
||||
'is_grouped' => TRUE,
|
||||
'group_info' => [
|
||||
'label' => 'list-text (field_list_text)',
|
||||
'description' => '',
|
||||
'identifier' => 'field_test_list_string_value',
|
||||
'optional' => TRUE,
|
||||
'widget' => 'radios',
|
||||
'multiple' => TRUE,
|
||||
'remember' => FALSE,
|
||||
'default_group' => '1',
|
||||
'group_items' => [
|
||||
1 => [
|
||||
'title' => 'First',
|
||||
'operator' => 'or',
|
||||
'value' => [
|
||||
$this->fieldValues[0] => $this->fieldValues[0],
|
||||
]
|
||||
],
|
||||
2 => [
|
||||
'title' => 'Second',
|
||||
'operator' => 'or',
|
||||
'value' => [
|
||||
$this->fieldValues[1] => $this->fieldValues[1],
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
'reduce_duplicates' => '',
|
||||
'plugin_id' => 'list_field',
|
||||
]
|
||||
];
|
||||
$view->setDisplay();
|
||||
$view->displayHandlers->get('default')->overrideOption('filters', $filters);
|
||||
|
||||
$view->storage->save();
|
||||
|
||||
$this->executeView($view);
|
||||
|
||||
$resultset = [
|
||||
['nid' => $this->nodes[0]->nid->value],
|
||||
['nid' => $this->nodes[1]->nid->value],
|
||||
];
|
||||
|
||||
$column_map = ['nid' => 'nid'];
|
||||
$this->assertIdenticalResultset($view, $resultset, $column_map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue