diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index 07cf1151e57d2faf9d0b809ecf36bdac33efd80e..5497efb3ef2040be00f7f9973abf383578582a86 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -871,7 +871,7 @@ protected function doLoadFieldItems($entities, $age) { $delta_count[$row->entity_id][$row->langcode] = 0; } - if ($field->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->getFieldCardinality()) { + if ($field->getFieldCardinality() == FieldInterface::CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->getFieldCardinality()) { $item = array(); // For each column declared by the field, populate the item from the // prefixed database column. @@ -953,7 +953,7 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) { $query->values($record); $revision_query->values($record); - if ($field->getFieldCardinality() != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field->getFieldCardinality()) { + if ($field->getFieldCardinality() != FieldInterface::CARDINALITY_UNLIMITED && ++$delta_count == $field->getFieldCardinality()) { break; } } diff --git a/core/lib/Drupal/Core/Field/ConfigFieldItemList.php b/core/lib/Drupal/Core/Field/ConfigFieldItemList.php index 2e32802b123690ca2f4e18eab408b24ae1bf5f76..49e49d24107a872fae62940b76416aae5f18aab9 100644 --- a/core/lib/Drupal/Core/Field/ConfigFieldItemList.php +++ b/core/lib/Drupal/Core/Field/ConfigFieldItemList.php @@ -61,7 +61,7 @@ public function getConstraints() { // form submitted values, this can only happen with 'multiple value' // widgets. $cardinality = $this->getFieldDefinition()->getFieldCardinality(); - if ($cardinality != FIELD_CARDINALITY_UNLIMITED) { + if ($cardinality != FieldDefinitionInterface::CARDINALITY_UNLIMITED) { $constraints[] = \Drupal::typedData() ->getValidationConstraintManager() ->create('Count', array( diff --git a/core/lib/Drupal/Core/Field/FieldDefinition.php b/core/lib/Drupal/Core/Field/FieldDefinition.php index 07551666053333ab0f9295cdbd0ee5677f742aed..8e57f7c47f064b81336afed927d1afdef5a7f02f 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -188,6 +188,14 @@ public function isFieldRequired() { return !empty($this->definition['required']); } + /** + * {@inheritdoc} + */ + public function isFieldMultiple() { + $cardinality = $this->getFieldCardinality(); + return ($cardinality == static::CARDINALITY_UNLIMITED) || ($cardinality > 1); + } + /** * Sets whether the field is required. * diff --git a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php index 3bab0d7f8dc8540f8563d0327876b37fab746ae9..bdaf247ea1f43c003742b1f0782039400ffff4a8 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -53,6 +53,11 @@ */ interface FieldDefinitionInterface { + /** + * Value indicating a field accepts an unlimited number of values. + */ + const CARDINALITY_UNLIMITED = -1; + /** * Returns the machine name of the field. * @@ -151,7 +156,8 @@ public function getFieldDescription(); /** * Returns the maximum number of items allowed for the field. * - * Possible values are positive integers or FIELD_CARDINALITY_UNLIMITED. + * Possible values are positive integers or + * FieldDefinitionInterface::CARDINALITY_UNLIMITED. * * @return integer * The field cardinality. @@ -169,6 +175,14 @@ public function getFieldCardinality(); */ public function isFieldRequired(); + /** + * Returns whether the field can contain multiple items. + * + * @return bool + * TRUE if the field can contain multiple items, FALSE otherwise. + */ + public function isFieldMultiple(); + /** * Returns the default value for the field in a newly created entity. * diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php index 4c78b04b365312b4583844fe2b9227b13e2a31f4..612e668e7c057446d48f1c7f140e046a6667029e 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -146,7 +146,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f // Determine the number of widgets to display. switch ($cardinality) { - case FIELD_CARDINALITY_UNLIMITED: + case FieldDefinitionInterface::CARDINALITY_UNLIMITED: $field_state = field_form_get_state($parents, $field_name, $form_state); $max = $field_state['items_count']; $is_multiple = TRUE; @@ -200,6 +200,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f '#theme' => 'field_multiple_value_form', '#field_name' => $field_name, '#cardinality' => $cardinality, + '#cardinality_multiple' => $this->fieldDefinition->isFieldMultiple(), '#required' => $this->fieldDefinition->isFieldRequired(), '#title' => $title, '#description' => $description, @@ -209,7 +210,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f ); // Add 'add more' button, if not working with a programmed form. - if ($cardinality == FIELD_CARDINALITY_UNLIMITED && empty($form_state['programmed'])) { + if ($cardinality == FieldDefinitionInterface::CARDINALITY_UNLIMITED && empty($form_state['programmed'])) { $elements['add_more'] = array( '#type' => 'submit', '#name' => strtr($id_prefix, '-', '_') . '_add_more', @@ -404,9 +405,7 @@ public function massageFormValues(array $values, array $form, array &$form_state * The field values. */ protected function sortItems(FieldItemListInterface $items) { - $cardinality = $this->fieldDefinition->getFieldCardinality(); - $is_multiple = ($cardinality == FIELD_CARDINALITY_UNLIMITED) || ($cardinality > 1); - if ($is_multiple && isset($items[0]->_weight)) { + if ($this->fieldDefinition->isFieldMultiple() && isset($items[0]->_weight)) { $itemValues = $items->getValue(TRUE); usort($itemValues, function ($a, $b) { $a_weight = (is_array($a) ? $a['_weight'] : 0); diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php index c89b34698431623a238d51c5b9f7fdc42d561431..2eb3c7d5041a93cba95c6726d56ccfab5885e1f7 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php @@ -7,6 +7,7 @@ namespace Drupal\edit\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; @@ -83,7 +84,7 @@ function setUp() { 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', // Set cardinality to unlimited for tagging. - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index f07a6ee42577f98d5a01ed02a4451ddf9677cc69..b2879dcd0ce9cac7da85434508b8194f0a8eeaba 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -7,6 +7,7 @@ namespace Drupal\entity_reference\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; @@ -44,7 +45,7 @@ function setUp() { 'target_type' => 'node', ), 'type' => 'entity_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ))->save(); entity_create('field_instance', array( diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index db6f33924d38985c6e9717c634c1d00fd9f020cd..b85380eddc2c25905a466fc9bc4a26ec7eeccb68 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -497,6 +497,8 @@ function field_read_instances($conditions = array(), $include_additional = array * // Only for 'single' widgets: * '#theme' => 'field_multiple_value_form', * '#cardinality' => The field cardinality, + * '#cardinality_multiple => TRUE if the field can contain multiple items, + * FALSE otherwise. * // One sub-array per copy of the widget, keyed by delta. * 0 => array( * '#entity_type' => The name of the entity type, diff --git a/core/modules/field/field.form.inc b/core/modules/field/field.form.inc index e5aa0bebae9ba4786862d7736f7072d06a8f1213..ebdc3d77235c0edce55600a8e4b195ab22e24493 100644 --- a/core/modules/field/field.form.inc +++ b/core/modules/field/field.form.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Field\FieldDefinitionInterface; /** * Returns HTML for an individual form element. @@ -24,7 +25,7 @@ function theme_field_multiple_value_form($variables) { $element = $variables['element']; $output = ''; - if ($element['#cardinality'] > 1 || $element['#cardinality'] == FIELD_CARDINALITY_UNLIMITED) { + if ($element['#cardinality_multiple']) { $form_required_marker = array('#theme' => 'form_required_marker'); $required = !empty($element['#required']) ? drupal_render($form_required_marker) : ''; $table_id = drupal_html_id($element['#field_name'] . '_values'); @@ -173,7 +174,7 @@ function field_add_more_js($form, $form_state) { $element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1)); // Ensure the widget allows adding additional items. - if ($element['#cardinality'] != FIELD_CARDINALITY_UNLIMITED) { + if ($element['#cardinality'] != FieldDefinitionInterface::CARDINALITY_UNLIMITED) { return; } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 2f0de84b72a0e1b613eb008845f88ccfaf7e4501..6d314b2f1a35a5ccb8a2ad2cd5a462a0971198ac 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -75,11 +75,6 @@ * multilingual support for the Field API. */ -/** - * Value for field API indicating a field accepts an unlimited number of values. - */ -const FIELD_CARDINALITY_UNLIMITED = -1; - /** * Implements hook_help(). */ diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index 6d1f488f61c43369a6792882d636dc84128bcd7e..b2f33c133bf9084739c7a4802e8fa66ced265274 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -377,7 +377,7 @@ function field_views_field_default_views_data(FieldInterface $field) { } // Expose additional delta column for multiple value fields. - if ($field->getFieldCardinality() > 1 || $field->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED) { + if ($field->isFieldMultiple()) { $title_delta = t('@label (!name:delta)', array('@label' => $label, '!name' => $field_name)); $title_short_delta = t('@label:delta', array('@label' => $label)); diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/Field.php index 6fb8ab7747bfce4b47f038319c1ed81b45dc7cf5..0a8d1a4e002bf301e009ba66ba3bdb39c3783e28 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -120,7 +120,8 @@ class Field extends ConfigEntityBase implements FieldInterface { * The field cardinality. * * The maximum number of values the field can hold. Possible values are - * positive integers or FIELD_CARDINALITY_UNLIMITED. Defaults to 1. + * positive integers or FieldDefinitionInterface::CARDINALITY_UNLIMITED. + * Defaults to 1. * * @var integer */ @@ -597,6 +598,14 @@ public function isFieldRequired() { return FALSE; } + /** + * {@inheritdoc} + */ + public function isFieldMultiple() { + $cardinality = $this->getFieldCardinality(); + return ($cardinality == static::CARDINALITY_UNLIMITED) || ($cardinality > 1); + } + /** * {@inheritdoc} */ diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php index 65013c0eb72ad0cff49e41365ad9527353a1a38a..6d43b630f94e2deb96b400ca99a29fb4e1d06096 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php @@ -584,6 +584,13 @@ public function isFieldRequired() { return $this->required; } + /** + * {@inheritdoc} + */ + public function isFieldMultiple() { + return $this->field->isFieldMultiple(); + } + /** * {@inheritdoc} */ diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 995bc9eab212138f7841acda4dcbf0e9d4f978f3..0d4d78eaf9c6cc34309f4eea67abf39530e7b65e 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityStorageControllerInterface; use Drupal\Core\Entity\FieldableDatabaseStorageController; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterPluginManager; use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; @@ -141,7 +142,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o $this->limit_values = FALSE; $cardinality = $field->getFieldCardinality(); - if ($cardinality > 1 || $cardinality == FIELD_CARDINALITY_UNLIMITED) { + if ($field->isFieldMultiple()) { $this->multiple = TRUE; // If "Display all values in the same row" is FALSE, then we always limit @@ -500,7 +501,7 @@ function multiple_options_form(&$form, &$form_state) { // translating prefix and suffix separately. list($prefix, $suffix) = explode('@count', t('Display @count value(s)')); - if ($field->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED) { + if ($field->getFieldCardinality() == FieldDefinitionInterface::CARDINALITY_UNLIMITED) { $type = 'textfield'; $options = NULL; $size = 5; diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 6fe20eb6b14a2947fd6d3ebd089d142ef7faf376..0f57fcefa20dbb5f430af42abf5a439709f6ab5a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; + class FormTest extends FieldTestBase { /** @@ -73,7 +75,7 @@ function setUp() { 'name' => 'field_unlimited', 'entity_type' => 'entity_test', 'type' => 'test_field', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ); $this->instance = array( diff --git a/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php b/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php index ad2b9586b7e6c8e6004df34b27df1bb982324f92..5da9ec0c90b49287b50e08fdd2ffbe825d6ea46c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/NestedFormTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; + class NestedFormTest extends FieldTestBase { /** @@ -39,7 +41,7 @@ public function setUp() { 'name' => 'field_unlimited', 'entity_type' => 'entity_test', 'type' => 'test_field', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ); $this->instance = array( diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php index 7f157e2ed810e2fb2144c0ae2bbcbd7ffc26bedc..3bed1b98a38ad7f76e690b9e226451cb1c4e9c93 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\field\Tests\Views; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\views\ViewExecutable; @@ -51,7 +52,7 @@ protected function setUp() { 'name' => 'field_name_3', 'entity_type' => 'node', 'type' => 'text', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, )); $field->save(); // Setup a field that will have no value. @@ -59,7 +60,7 @@ protected function setUp() { 'name' => 'field_name_4', 'entity_type' => 'node', 'type' => 'text', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, )); $field->save(); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 1f277f51602edc8d6a0eef958bb07233fc74e8f9..4f426ea21a71d06d8ce17273856eb495ee315dab 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -123,13 +123,13 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac '#title_display' => 'invisible', '#options' => array( 'number' => $this->t('Limited'), - FIELD_CARDINALITY_UNLIMITED => $this->t('Unlimited'), + FieldInstanceInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited'), ), - '#default_value' => ($cardinality == FIELD_CARDINALITY_UNLIMITED) ? FIELD_CARDINALITY_UNLIMITED : 'number', + '#default_value' => ($cardinality == FieldInstanceInterface::CARDINALITY_UNLIMITED) ? FieldInstanceInterface::CARDINALITY_UNLIMITED : 'number', ); $form['field']['cardinality_container']['cardinality_number'] = array( '#type' => 'number', - '#default_value' => $cardinality != FIELD_CARDINALITY_UNLIMITED ? $cardinality : 1, + '#default_value' => $cardinality != FieldInstanceInterface::CARDINALITY_UNLIMITED ? $cardinality : 1, '#min' => 1, '#title' => $this->t('Limit'), '#title_display' => 'invisible', diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index e3d6e319ac926ad0b5aad7d475c35cc0b3496b6d..502aef3fe49aaa201260b81227092e5711c9d6e9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -7,6 +7,7 @@ namespace Drupal\field_ui\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\Component\Utility\String; @@ -201,12 +202,12 @@ function cardinalitySettings() { // Set to unlimited. $edit = array( - 'field[cardinality]' => FIELD_CARDINALITY_UNLIMITED, + 'field[cardinality]' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ); $this->drupalPostForm($field_edit_path, $edit, t('Save field settings')); $this->assertText('Updated field Body field settings.'); $this->drupalGet($field_edit_path); - $this->assertFieldByXPath("//select[@name='field[cardinality]']", FIELD_CARDINALITY_UNLIMITED); + $this->assertFieldByXPath("//select[@name='field[cardinality]']", FieldDefinitionInterface::CARDINALITY_UNLIMITED); $this->assertFieldByXPath("//input[@name='field[cardinality_number]']", 1); } diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php index 809cc08d845715e3087987b554f330e43d69a12e..7ce14b8b3f2e63fb41c84194ee645e3d469bf795 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php @@ -7,6 +7,7 @@ namespace Drupal\file\Plugin\Field\FieldWidget; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Field\FieldItemListInterface; @@ -74,7 +75,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f // Determine the number of widgets to display. $cardinality = $this->fieldDefinition->getFieldCardinality(); switch ($cardinality) { - case FIELD_CARDINALITY_UNLIMITED: + case FieldDefinitionInterface::CARDINALITY_UNLIMITED: $max = count($items); $is_multiple = TRUE; break; @@ -121,7 +122,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f } $empty_single_allowed = ($cardinality == 1 && $delta == 0); - $empty_multiple_allowed = ($cardinality == FIELD_CARDINALITY_UNLIMITED || $delta < $cardinality) && empty($form_state['programmed']); + $empty_multiple_allowed = ($cardinality == FieldDefinitionInterface::CARDINALITY_UNLIMITED || $delta < $cardinality) && empty($form_state['programmed']); // Add one more empty row for new uploads except when this is a programmed // multiple form as it is not necessary. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index 18bead4afcdd093ce77513b6d39f58e059e1bb14..d4e27f562ade389d0fbb4eb9336140cdd7a4b78a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -7,6 +7,7 @@ namespace Drupal\file\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\field\Field; /** @@ -52,7 +53,7 @@ function testRequired() { // Try again with a multiple value field. $field->delete(); - $this->createFileField($field_name, 'node', $type_name, array('cardinality' => FIELD_CARDINALITY_UNLIMITED), array('required' => '1')); + $this->createFileField($field_name, 'node', $type_name, array('cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED), array('required' => '1')); // Try to post a new node without uploading a file in the multivalue field. $edit = array('title' => $this->randomName()); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php index 22f2b47b99dc9c4694e8b0b54c66216689826c7a..322d4452edec9929a20761c882f294f886107008 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileItemTest.php @@ -7,6 +7,7 @@ namespace Drupal\file\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\field\Tests\FieldUnitTestBase; @@ -48,7 +49,7 @@ public function setUp() { 'name' => 'file_test', 'entity_type' => 'entity_test', 'type' => 'file', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ))->save(); entity_create('field_instance', array( 'entity_type' => 'entity_test', diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php index ebdb1c78c104d6ab988d4319cdc4a2f5a1054cf0..ee2581d54427cade78ea39752452b25da5f4d9e7 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageItemTest.php @@ -7,6 +7,7 @@ namespace Drupal\image\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\field\Tests\FieldUnitTestBase; @@ -52,7 +53,7 @@ public function setUp() { 'name' => 'image_test', 'entity_type' => 'entity_test', 'type' => 'image', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ))->save(); entity_create('field_instance', array( 'entity_type' => 'entity_test', diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php index 0ee9de29ae15a1ee64dbc4d9ee1a85f816e7333b..166f4766902f4636bd95559864a4f0575f16cf1f 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldWidget/OptionsWidgetBase.php @@ -58,8 +58,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Prepare some properties for the child methods to build the actual form // element. $this->required = $element['#required']; - $cardinality = $this->fieldDefinition->getFieldCardinality(); - $this->multiple = ($cardinality == FIELD_CARDINALITY_UNLIMITED) || ($cardinality > 1); + $this->multiple = $this->fieldDefinition->isFieldMultiple(); $this->has_value = isset($items[0]->{$this->column}); // Add our custom validator. diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php index 0f157904126ab2b5e019c927e485a1b2636528f7..274b5aacafc4c8b570f9173369c89560bb4073d4 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/Field/TaxonomyTermReferenceRdfaTest.php @@ -7,6 +7,7 @@ namespace Drupal\rdf\Tests\Field; use Drupal\rdf\Tests\Field\FieldRdfaTestBase; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; /** @@ -62,7 +63,7 @@ public function setUp() { 'name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php index 9d621680a27e2b7cec62da57e85d2f3bdbad5fe0..f19cff2e99e393d66616f8f55637a16eafcbe003 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TaxonomyTermFieldAttributesTest.php @@ -7,6 +7,7 @@ namespace Drupal\rdf\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\taxonomy\Tests\TaxonomyTestBase; /** @@ -158,7 +159,7 @@ protected function createTaxonomyTermReferenceField($field_name, $vocabulary) { 'name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php index 7709d64ae5fb1929f2093765668c2ecc32b46ff0..1e3dbd3cd4c51ff00db8c52c687d9dc3f3b7cff3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/MultiFormTest.php @@ -7,6 +7,8 @@ namespace Drupal\system\Tests\Ajax; +use Drupal\Core\Field\FieldDefinitionInterface; + /** * Tests Ajax-enabled forms functionality with multiple instances of the form. */ @@ -38,7 +40,7 @@ function setUp() { 'name' => $field_name, 'entity_type' => 'node', 'type' => 'text', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ))->save(); entity_create('field_instance', array( 'field_name' => $field_name, diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php index 163e5df25174a2fa6f0b8278b25f36a466d49db0..a05e6841a2a7c37756d9843c406d9c28c27e7ee7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/RebuildTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Form; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\simpletest\WebTestBase; /** @@ -75,7 +76,7 @@ function testPreserveFormActionAfterAJAX() { 'name' => $field_name, 'entity_type' => 'node', 'type' => 'text', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, ); entity_create('field_entity', $field)->save(); $instance = array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index 654ea15abaa46592b24f789335d6ca7ffab14a9c..e89c531370c0684e911101f10f48b60522509969 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; + /** * Tests the rendering of term reference fields in RSS feeds. */ @@ -39,7 +41,7 @@ function setUp() { 'name' => $this->field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php index 1b989bdefdc67f24843d5d1b48d9b0341b09773d..df4255650cf259a2c5704acbe3f9eb7ca14bf935 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php @@ -7,9 +7,10 @@ namespace Drupal\taxonomy\Tests; -use Drupal\Core\Language\Language; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemInterface; +use Drupal\Core\Language\Language; use Drupal\field\Tests\FieldUnitTestBase; /** @@ -48,7 +49,7 @@ public function setUp() { 'name' => 'field_test_taxonomy', 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 9ddb3c47dcb4f5fba1ff43c6d345563ea4eff592..18e218435bbf7fa8cc86e1c6f781f36b395d87b5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; + /** * Tests a taxonomy term reference field that allows multiple vocabularies. */ @@ -44,7 +46,7 @@ function setUp() { 'name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index 686b4ebf905a8e57ae3bfc9fe61d09f06d8dbaf9..c7abc5c987fe5e2f8f7fa5f1968f4b8b63b9bbb7 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; + /** * Tests the hook implementations that maintain the taxonomy index. */ @@ -35,7 +37,7 @@ function setUp() { 'name' => $this->field_name_1, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( @@ -66,7 +68,7 @@ function setUp() { 'name' => $this->field_name_2, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index d11eefe3c9f1b1a70614411f88587068d6fdfeef..26f04adb6f8c3f974f562646c0081f68ff380598 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; + /** * Tests for taxonomy term functions. */ @@ -31,7 +33,7 @@ function setUp() { 'name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index fb501e598fb412340b611abfb2c4d3cf592a5f78..be4ed5371190215f1f9488c7154ea5fa51af172d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; /** @@ -32,7 +33,7 @@ function setUp() { 'name' => $this->field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php index 6e7d3932abb443ec573f41b197ce664c1cc61b0e..b44e6c514b517dcdb743a2c2dca0adeae6885311 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests\Views; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestData; @@ -82,7 +83,7 @@ protected function mockStandardInstall() { 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', // Set cardinality to unlimited for tagging. - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array( diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 34b348b49eca9f08d201c3ace94b07745cfbfb27..d952f8c7745aa0edae2c014017964e93448fa516 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; @@ -251,7 +252,7 @@ function testRegistrationWithUserFields() { $this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correclty saved.'); // Check that the 'add more' button works. - $field->cardinality = FIELD_CARDINALITY_UNLIMITED; + $field->cardinality = FieldDefinitionInterface::CARDINALITY_UNLIMITED; $field->save(); foreach (array('js', 'nojs') as $js) { $this->drupalGet('user/register'); diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php index 497af62b6919e4c636f673961923abe7c65ddf2b..8a046048bbbd810af0e338b076a6b683b5ae2373 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -7,6 +7,8 @@ namespace Drupal\views\Tests\Wizard; +use Drupal\Core\Field\FieldDefinitionInterface; + /** * Tests the ability of the views wizard to create views filtered by taxonomy. */ @@ -57,7 +59,7 @@ function setUp() { 'name' => 'field_views_testing_tags', 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', - 'cardinality' => FIELD_CARDINALITY_UNLIMITED, + 'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array( 'allowed_values' => array( array(