diff --git a/core/includes/form.inc b/core/includes/form.inc
index 70870ce..78a4f7a 100644
--- a/core/includes/form.inc
+++ b/core/includes/form.inc
@@ -11,6 +11,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Database\Database;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\OptGroup;
use Drupal\Core\Render\Element;
@@ -19,11 +20,6 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
- * Identifies a 'None' option key.
- */
-const OPTIONS_EMPTY_OPTION = '_none';
-
-/**
* Retrieves, populates, and processes a form.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
@@ -62,78 +58,11 @@ function template_preprocess_select(&$variables) {
/**
* Converts an array of options into HTML, for use in select list form elements.
*
- * This function calls itself recursively to obtain the values for each optgroup
- * within the list of options and when the function encounters an object with
- * an 'options' property inside $element['#options'].
- *
- * @param array $element
- * An associative array containing the following key-value pairs:
- * - #multiple: Optional Boolean indicating if the user may select more than
- * one item.
- * - #options: An associative array of options to render as HTML. Each array
- * value can be a string, an array, or an object with an 'option' property:
- * - A string or integer key whose value is a translated string is
- * interpreted as a single HTML option element. Do not use placeholders
- * that sanitize data: doing so will lead to double-escaping. Note that
- * the key will be visible in the HTML and could be modified by malicious
- * users, so don't put sensitive information in it.
- * - A translated string key whose value is an array indicates a group of
- * options. The translated string is used as the label attribute for the
- * optgroup. Do not use placeholders to sanitize data: doing so will lead
- * to double-escaping. The array should contain the options you wish to
- * group and should follow the syntax of $element['#options'].
- * - If the function encounters a string or integer key whose value is an
- * object with an 'option' property, the key is ignored, the contents of
- * the option property are interpreted as $element['#options'], and the
- * resulting HTML is added to the output.
- * - #value: Optional integer, string, or array representing which option(s)
- * to pre-select when the list is first displayed. The integer or string
- * must match the key of an option in the '#options' list. If '#multiple' is
- * TRUE, this can be an array of integers or strings.
- * @param array|null $choices
- * (optional) Either an associative array of options in the same format as
- * $element['#options'] above, or NULL. This parameter is only used internally
- * and is not intended to be passed in to the initial function call.
- *
- * @return string
- * An HTML string of options and optgroups for use in a select form element.
+ * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 8.0.0.
+ * Use \Drupal\Core\Form\FormOptionsHelper::formSelectOptions().
*/
function form_select_options($element, $choices = NULL) {
- if (!isset($choices)) {
- if (empty($element['#options'])) {
- return '';
- }
- $choices = $element['#options'];
- }
- // array_key_exists() accommodates the rare event where $element['#value'] is NULL.
- // isset() fails in this situation.
- $value_valid = isset($element['#value']) || array_key_exists('#value', $element);
- $value_is_array = $value_valid && is_array($element['#value']);
- // Check if the element is multiple select and no value has been selected.
- $empty_value = (empty($element['#value']) && !empty($element['#multiple']));
- $options = '';
- foreach ($choices as $key => $choice) {
- if (is_array($choice)) {
- $options .= '';
- }
- elseif (is_object($choice) && isset($choice->option)) {
- $options .= form_select_options($element, $choice->option);
- }
- else {
- $key = (string) $key;
- $empty_choice = $empty_value && $key == OPTIONS_EMPTY_OPTION;
- if ($value_valid && ((!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value']))) || $empty_choice)) {
- $selected = ' selected="selected"';
- }
- else {
- $selected = '';
- }
- $options .= '';
- }
- }
- return SafeMarkup::set($options);
+ return FormOptionsHelper::formSelectOptions($element, $choices);
}
/**
diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
index 267e0f4..87b8257 100644
--- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
+++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/SelectionBase.php
@@ -12,6 +12,7 @@
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -113,7 +114,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$selection_handler_settings += array(
'target_bundles' => array(),
'sort' => array(
- 'field' => OPTIONS_EMPTY_OPTION,
+ 'field' => FormOptionsHelper::OPTIONS_EMPTY_OPTION,
),
'auto_create' => FALSE,
);
@@ -169,7 +170,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#type' => 'select',
'#title' => $this->t('Sort by'),
'#options' => array(
- OPTIONS_EMPTY_OPTION => $this->t('- None -'),
+ FormOptionsHelper::OPTIONS_EMPTY_OPTION => $this->t('- None -'),
) + $fields,
'#ajax' => TRUE,
'#limit_validation_errors' => array(),
@@ -182,7 +183,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#process' => array('_entity_reference_form_process_merge_parent'),
);
- if ($selection_handler_settings['sort']['field'] != OPTIONS_EMPTY_OPTION) {
+ if ($selection_handler_settings['sort']['field'] != FormOptionsHelper::OPTIONS_EMPTY_OPTION) {
// Merge-in default values.
$selection_handler_settings['sort'] += array(
'direction' => 'ASC',
@@ -345,7 +346,7 @@ protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS')
// Add the sort option.
if (!empty($handler_settings['sort'])) {
$sort_settings = $handler_settings['sort'];
- if ($sort_settings['field'] != OPTIONS_EMPTY_OPTION) {
+ if ($sort_settings['field'] != FormOptionsHelper::OPTIONS_EMPTY_OPTION) {
$query->sort($sort_settings['field'], $sort_settings['direction']);
}
}
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
index 83cb9cc..06d4483 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
@@ -11,6 +11,7 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\OptGroup;
@@ -81,7 +82,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
* The form state.
*/
public static function validateElement(array $element, FormStateInterface $form_state) {
- if ($element['#required'] && $element['#value'] == OPTIONS_EMPTY_OPTION) {
+ if ($element['#required'] && $element['#value'] == FormOptionsHelper::OPTIONS_EMPTY_OPTION) {
$form_state->setError($element, t('!name field is required.', array('!name' => $element['#title'])));
}
@@ -99,7 +100,7 @@ public static function validateElement(array $element, FormStateInterface $form_
// Filter out the 'none' option. Use a strict comparison, because
// 0 == 'any string'.
- $index = array_search(OPTIONS_EMPTY_OPTION, $values, TRUE);
+ $index = array_search(FormOptionsHelper::OPTIONS_EMPTY_OPTION, $values, TRUE);
if ($index !== FALSE) {
unset($values[$index]);
}
@@ -141,7 +142,7 @@ protected function getOptions(FieldableEntityInterface $entity) {
break;
}
- $options = array(OPTIONS_EMPTY_OPTION => $label) + $options;
+ $options = array(FormOptionsHelper::OPTIONS_EMPTY_OPTION => $label) + $options;
}
$module_handler = \Drupal::moduleHandler();
diff --git a/core/lib/Drupal/Core/Form/FormOptionsHelper.php b/core/lib/Drupal/Core/Form/FormOptionsHelper.php
index 12e4d75..e3c2673 100644
--- a/core/lib/Drupal/Core/Form/FormOptionsHelper.php
+++ b/core/lib/Drupal/Core/Form/FormOptionsHelper.php
@@ -7,10 +7,93 @@
namespace Drupal\Core\Form;
+use Drupal\Component\Utility\SafeMarkup;
+
/**
* @todo.
*/
class FormOptionsHelper {
+ /**
+ * Identifies a 'None' option key.
+ */
+ const OPTIONS_EMPTY_OPTION = '_none';
+
+ /**
+ * Converts an array of options into HTML, for use in select list form elements.
+ *
+ * This function calls itself recursively to obtain the values for each optgroup
+ * within the list of options and when the function encounters an object with
+ * an 'options' property inside $element['#options'].
+ *
+ * @param array $element
+ * An associative array containing the following key-value pairs:
+ * - #multiple: Optional Boolean indicating if the user may select more than
+ * one item.
+ * - #options: An associative array of options to render as HTML. Each array
+ * value can be a string, an array, or an object with an 'option' property:
+ * - A string or integer key whose value is a translated string is
+ * interpreted as a single HTML option element. Do not use placeholders
+ * that sanitize data: doing so will lead to double-escaping. Note that
+ * the key will be visible in the HTML and could be modified by malicious
+ * users, so don't put sensitive information in it.
+ * - A translated string key whose value is an array indicates a group of
+ * options. The translated string is used as the label attribute for the
+ * optgroup. Do not use placeholders to sanitize data: doing so will lead
+ * to double-escaping. The array should contain the options you wish to
+ * group and should follow the syntax of $element['#options'].
+ * - If the function encounters a string or integer key whose value is an
+ * object with an 'option' property, the key is ignored, the contents of
+ * the option property are interpreted as $element['#options'], and the
+ * resulting HTML is added to the output.
+ * - #value: Optional integer, string, or array representing which option(s)
+ * to pre-select when the list is first displayed. The integer or string
+ * must match the key of an option in the '#options' list. If '#multiple' is
+ * TRUE, this can be an array of integers or strings.
+ * @param array|null $choices
+ * (optional) Either an associative array of options in the same format as
+ * $element['#options'] above, or NULL. This parameter is only used internally
+ * and is not intended to be passed in to the initial function call.
+ *
+ * @return string
+ * An HTML string of options and optgroups for use in a select form element.
+ */
+ public static function formSelectOptions(array $element, $choices = NULL) {
+ if (!isset($choices)) {
+ if (empty($element['#options'])) {
+ return '';
+ }
+ $choices = $element['#options'];
+ }
+ // array_key_exists() accommodates the rare event where $element['#value'] is NULL.
+ // isset() fails in this situation.
+ $value_valid = isset($element['#value']) || array_key_exists('#value', $element);
+ $value_is_array = $value_valid && is_array($element['#value']);
+ // Check if the element is multiple select and no value has been selected.
+ $empty_value = (empty($element['#value']) && !empty($element['#multiple']));
+ $options = '';
+ foreach ($choices as $key => $choice) {
+ if (is_array($choice)) {
+ $options .= '';
+ }
+ elseif (is_object($choice) && isset($choice->option)) {
+ $options .= static::formSelectOptions($element, $choice->option);
+ }
+ else {
+ $key = (string) $key;
+ $empty_choice = $empty_value && $key == static::OPTIONS_EMPTY_OPTION;
+ if ($value_valid && ((!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value']))) || $empty_choice)) {
+ $selected = ' selected="selected"';
+ }
+ else {
+ $selected = '';
+ }
+ $options .= '';
+ }
+ }
+ return SafeMarkup::set($options);
+ }
+
}
-
\ No newline at end of file
diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php
index f61c801..d8efae5 100644
--- a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php
+++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php
@@ -7,6 +7,7 @@
namespace Drupal\entity_reference\Tests;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
@@ -97,7 +98,7 @@ public function testFieldAdminHandler() {
// Test the sort settings.
// Option 0: no sort.
- $this->assertFieldByName('field[settings][handler_settings][sort][field]', OPTIONS_EMPTY_OPTION);
+ $this->assertFieldByName('field[settings][handler_settings][sort][field]', FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
// Option 1: sort by field.
$this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => 'nid'), 'field[settings][handler_settings][sort][field]');
@@ -111,7 +112,7 @@ public function testFieldAdminHandler() {
$this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='body.value']");
// Set back to no sort.
- $this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => OPTIONS_EMPTY_OPTION), 'field[settings][handler_settings][sort][field]');
+ $this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => FormOptionsHelper::OPTIONS_EMPTY_OPTION), 'field[settings][handler_settings][sort][field]');
$this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
// Third step: confirm.
@@ -147,7 +148,7 @@ public function testFieldAdminHandler() {
);
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
- $this->assertFieldByName('field[settings][handler_settings][filter][type]', OPTIONS_EMPTY_OPTION);
+ $this->assertFieldByName('field[settings][handler_settings][filter][type]', FormOptionsHelper::OPTIONS_EMPTY_OPTION);
// Try to select the views handler.
$edit = array(
diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php
index 642bfa0..4c6f0d6 100644
--- a/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php
+++ b/core/modules/entity_reference/src/Tests/EntityReferenceFieldDefaultValueTest.php
@@ -9,6 +9,7 @@
use Drupal\Component\Utility\Unicode;
use Drupal\config\Tests\SchemaCheckTestTrait;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\WebTestBase;
@@ -68,7 +69,7 @@ function testEntityReferenceDefaultValue() {
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array('referenced_content'),
- 'sort' => array('field' => OPTIONS_EMPTY_OPTION),
+ 'sort' => array('field' => FormOptionsHelper::OPTIONS_EMPTY_OPTION),
),
),
));
@@ -131,7 +132,7 @@ function testEntityReferenceDefaultConfigValue() {
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
- 'sort' => array('field' => OPTIONS_EMPTY_OPTION),
+ 'sort' => array('field' => FormOptionsHelper::OPTIONS_EMPTY_OPTION),
),
),
));
diff --git a/core/modules/options/options.api.php b/core/modules/options/options.api.php
index f54c4dd..c49ecd2 100644
--- a/core/modules/options/options.api.php
+++ b/core/modules/options/options.api.php
@@ -7,6 +7,7 @@
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Form\FormOptionsHelper;
/**
* Alters the list of options to be displayed for a field.
@@ -32,7 +33,7 @@ function hook_options_list_alter(array &$options, array $context) {
// Check if this is the field we want to change.
if ($context['field']->id() == 'field_option') {
// Change the label of the empty option.
- $options[OPTIONS_EMPTY_OPTION] = t('== Empty ==');
+ $options[FormOptionsHelper::OPTIONS_EMPTY_OPTION] = t('== Empty ==');
}
}
diff --git a/core/modules/options/src/Tests/OptionsSelectDynamicValuesTest.php b/core/modules/options/src/Tests/OptionsSelectDynamicValuesTest.php
index 844e81b..b27bfb4 100644
--- a/core/modules/options/src/Tests/OptionsSelectDynamicValuesTest.php
+++ b/core/modules/options/src/Tests/OptionsSelectDynamicValuesTest.php
@@ -7,6 +7,8 @@
namespace Drupal\options\Tests;
+use Drupal\Core\Form\FormOptionsHelper;
+
/**
* Tests an options select with a dynamic allowed values function.
*
@@ -30,7 +32,7 @@ function testSelectListDynamic() {
$this->assertEqual(count($options), count($this->test) + 1);
foreach ($options as $option) {
$value = (string) $option['value'];
- if ($value != OPTIONS_EMPTY_OPTION) {
+ if ($value != FormOptionsHelper::OPTIONS_EMPTY_OPTION) {
$this->assertTrue(array_search($value, $this->test));
}
}
diff --git a/core/modules/options/src/Tests/OptionsWidgetsTest.php b/core/modules/options/src/Tests/OptionsWidgetsTest.php
index a0a709a..f820614 100644
--- a/core/modules/options/src/Tests/OptionsWidgetsTest.php
+++ b/core/modules/options/src/Tests/OptionsWidgetsTest.php
@@ -7,6 +7,7 @@
namespace Drupal\options\Tests;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\field\Tests\FieldTestBase;
/**
@@ -127,7 +128,7 @@ function testRadioButtons() {
$this->assertNoFieldChecked('edit-card-1-2');
// Unselect option.
- $edit = array('card_1' => OPTIONS_EMPTY_OPTION);
+ $edit = array('card_1' => FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertFieldValues($entity_init, 'card_1', array());
@@ -257,17 +258,17 @@ function testSelectListSingle() {
// Display form.
$this->drupalGet('entity_test/manage/' . $entity->id());
// A required field without any value has a "none" option.
- $this->assertTrue($this->xpath('//select[@id=:id]//option[@value=:value and text()=:label]', array(':id' => 'edit-card-1', ':value' => OPTIONS_EMPTY_OPTION, ':label' => t('- Select a value -'))), 'A required select list has a "Select a value" choice.');
+ $this->assertTrue($this->xpath('//select[@id=:id]//option[@value=:value and text()=:label]', array(':id' => 'edit-card-1', ':value' => FormOptionsHelper::OPTIONS_EMPTY_OPTION, ':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', OPTIONS_EMPTY_OPTION);
+ $this->assertNoOptionSelected('edit-card-1', FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$this->assertNoOptionSelected('edit-card-1', 0);
$this->assertNoOptionSelected('edit-card-1', 1);
$this->assertNoOptionSelected('edit-card-1', 2);
$this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.');
// Submit form: select invalid 'none' option.
- $edit = array('card_1' => OPTIONS_EMPTY_OPTION);
+ $edit = array('card_1' => FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$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.');
@@ -279,7 +280,7 @@ function testSelectListSingle() {
// Display form: check that the right options are selected.
$this->drupalGet('entity_test/manage/' . $entity->id());
// A required field with a value has no 'none' option.
- $this->assertFalse($this->xpath('//select[@id=:id]//option[@value=:value]', array(':id' => 'edit-card-1', ':value' => OPTIONS_EMPTY_OPTION)), 'A required select list with an actual value has no "none" choice.');
+ $this->assertFalse($this->xpath('//select[@id=:id]//option[@value=:value]', array(':id' => 'edit-card-1', ':value' => FormOptionsHelper::OPTIONS_EMPTY_OPTION)), '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);
@@ -291,9 +292,9 @@ function testSelectListSingle() {
// Display form.
$this->drupalGet('entity_test/manage/' . $entity->id());
// A non-required field has a 'none' option.
- $this->assertTrue($this->xpath('//select[@id=:id]//option[@value=:value and text()=:label]', array(':id' => 'edit-card-1', ':value' => OPTIONS_EMPTY_OPTION, ':label' => t('- None -'))), 'A non-required select list has a "None" choice.');
+ $this->assertTrue($this->xpath('//select[@id=:id]//option[@value=:value and text()=:label]', array(':id' => 'edit-card-1', ':value' => FormOptionsHelper::OPTIONS_EMPTY_OPTION, ':label' => t('- None -'))), 'A non-required select list has a "None" choice.');
// Submit form: Unselect the option.
- $edit = array('card_1' => OPTIONS_EMPTY_OPTION);
+ $edit = array('card_1' => FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$this->drupalPostForm('entity_test/manage/' . $entity->id(), $edit, t('Save'));
$this->assertFieldValues($entity_init, 'card_1', array());
@@ -324,7 +325,7 @@ function testSelectListSingle() {
$this->assertNoOptionSelected('edit-card-1', 2);
// Submit form: Unselect the option.
- $edit = array('card_1' => OPTIONS_EMPTY_OPTION);
+ $edit = array('card_1' => FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$this->drupalPostForm('entity_test/manage/' . $entity->id(), $edit, t('Save'));
$this->assertFieldValues($entity_init, 'card_1', array());
}
@@ -355,7 +356,7 @@ function testSelectListMultiple() {
// Display form: with no field data, nothing is selected.
$this->drupalGet('entity_test/manage/' . $entity->id());
- $this->assertOptionSelected("edit-card-2", OPTIONS_EMPTY_OPTION);
+ $this->assertOptionSelected("edit-card-2", FormOptionsHelper::OPTIONS_EMPTY_OPTION);
$this->assertNoOptionSelected('edit-card-2', 0);
$this->assertNoOptionSelected('edit-card-2', 1);
$this->assertNoOptionSelected('edit-card-2', 2);
@@ -397,12 +398,12 @@ function testSelectListMultiple() {
// Check that the 'none' option has no effect if actual options are selected
// as well.
- $edit = array('card_2[]' => array(OPTIONS_EMPTY_OPTION => OPTIONS_EMPTY_OPTION, 0 => 0));
+ $edit = array('card_2[]' => array(FormOptionsHelper::OPTIONS_EMPTY_OPTION => FormOptionsHelper::OPTIONS_EMPTY_OPTION, 0 => 0));
$this->drupalPostForm('entity_test/manage/' . $entity->id(), $edit, t('Save'));
$this->assertFieldValues($entity_init, 'card_2', array(0));
// Check that selecting the 'none' option empties the field.
- $edit = array('card_2[]' => array(OPTIONS_EMPTY_OPTION => OPTIONS_EMPTY_OPTION));
+ $edit = array('card_2[]' => array(FormOptionsHelper::OPTIONS_EMPTY_OPTION => FormOptionsHelper::OPTIONS_EMPTY_OPTION));
$this->drupalPostForm('entity_test/manage/' . $entity->id(), $edit, t('Save'));
$this->assertFieldValues($entity_init, 'card_2', array());
@@ -445,7 +446,7 @@ function testSelectListMultiple() {
$this->assertNoOptionSelected('edit-card-2', 2);
// Submit form: Unselect the option.
- $edit = array('card_2[]' => array(OPTIONS_EMPTY_OPTION => OPTIONS_EMPTY_OPTION));
+ $edit = array('card_2[]' => array(FormOptionsHelper::OPTIONS_EMPTY_OPTION => FormOptionsHelper::OPTIONS_EMPTY_OPTION));
$this->drupalPostForm('entity_test/manage/' . $entity->id(), $edit, t('Save'));
$this->assertFieldValues($entity_init, 'card_2', array());
}
diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
index a63079e..78b8577 100644
--- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
@@ -10,6 +10,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
@@ -244,7 +245,7 @@ protected function createReferenceTestEntities($referenced_entity) {
'target_bundles' => array(
$referenced_entity->bundle() => $referenced_entity->bundle(),
),
- 'sort' => array('field' => OPTIONS_EMPTY_OPTION),
+ 'sort' => array('field' => FormOptionsHelper::OPTIONS_EMPTY_OPTION),
'auto_create' => FALSE,
),
),
diff --git a/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
index 9675da6..192ac9c 100644
--- a/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
+++ b/core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php
@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Form\FormOptionsHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\RoleInterface;
@@ -85,7 +86,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
// Merge in default values.
$selection_handler_settings += array(
'filter' => array(
- 'type' => OPTIONS_EMPTY_OPTION,
+ 'type' => FormOptionsHelper::OPTIONS_EMPTY_OPTION,
),
'include_anonymous' => TRUE,
);
@@ -101,7 +102,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#type' => 'select',
'#title' => $this->t('Filter by'),
'#options' => array(
- OPTIONS_EMPTY_OPTION => $this->t('- None -'),
+ FormOptionsHelper::OPTIONS_EMPTY_OPTION => $this->t('- None -'),
'role' => $this->t('User role'),
),
'#ajax' => TRUE,