From 840e20aec621eb83a4a32876e68935d9856eb16f Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sat, 26 Oct 2013 09:26:00 -0700 Subject: [PATCH] Issue #2097691 by plopesc, amateescu: Move FIELD_CARDINALITY_UNLIMITED constant to FieldDefinitionInterface. --- .../FieldableDatabaseStorageController.php | 4 ++-- .../Drupal/Core/Field/ConfigFieldItemList.php | 2 +- core/lib/Drupal/Core/Field/FieldDefinition.php | 8 ++++++++ .../Core/Field/FieldDefinitionInterface.php | 16 +++++++++++++++- core/lib/Drupal/Core/Field/WidgetBase.php | 9 ++++----- .../edit/Tests/EditAutocompleteTermTest.php | 3 ++- .../Tests/EntityReferenceAutoCreateTest.php | 3 ++- core/modules/field/field.deprecated.inc | 2 ++ core/modules/field/field.form.inc | 5 +++-- core/modules/field/field.module | 5 ----- core/modules/field/field.views.inc | 2 +- .../field/lib/Drupal/field/Entity/Field.php | 11 ++++++++++- .../lib/Drupal/field/Entity/FieldInstance.php | 7 +++++++ .../Drupal/field/Plugin/views/field/Field.php | 5 +++-- .../field/lib/Drupal/field/Tests/FormTest.php | 4 +++- .../lib/Drupal/field/Tests/NestedFormTest.php | 4 +++- .../field/Tests/Views/HandlerFieldFieldTest.php | 5 +++-- .../lib/Drupal/field_ui/Form/FieldEditForm.php | 6 +++--- .../Drupal/field_ui/Tests/ManageFieldsTest.php | 5 +++-- .../file/Plugin/Field/FieldWidget/FileWidget.php | 5 +++-- .../Drupal/file/Tests/FileFieldValidateTest.php | 3 ++- .../file/lib/Drupal/file/Tests/FileItemTest.php | 3 ++- .../lib/Drupal/image/Tests/ImageItemTest.php | 3 ++- .../Field/FieldWidget/OptionsWidgetBase.php | 3 +-- .../Field/TaxonomyTermReferenceRdfaTest.php | 3 ++- .../Tests/TaxonomyTermFieldAttributesTest.php | 3 ++- .../Drupal/system/Tests/Ajax/MultiFormTest.php | 4 +++- .../lib/Drupal/system/Tests/Form/RebuildTest.php | 3 ++- .../lib/Drupal/taxonomy/Tests/RssTest.php | 4 +++- .../Tests/TaxonomyTermReferenceItemTest.php | 5 +++-- .../Tests/TermFieldMultipleVocabularyTest.php | 4 +++- .../lib/Drupal/taxonomy/Tests/TermIndexTest.php | 6 ++++-- .../lib/Drupal/taxonomy/Tests/TermTest.php | 4 +++- .../Drupal/taxonomy/Tests/TokenReplaceTest.php | 3 ++- .../taxonomy/Tests/Views/TaxonomyTestBase.php | 3 ++- .../Drupal/user/Tests/UserRegistrationTest.php | 3 ++- .../Drupal/views/Tests/Wizard/TaggedWithTest.php | 4 +++- 37 files changed, 119 insertions(+), 53 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index 07cf1151e57..5497efb3ef2 100644 --- a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php @@ -871,7 +871,7 @@ class FieldableDatabaseStorageController extends FieldableEntityStorageControlle $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 @@ class FieldableDatabaseStorageController extends FieldableEntityStorageControlle $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 2e32802b123..49e49d24107 100644 --- a/core/lib/Drupal/Core/Field/ConfigFieldItemList.php +++ b/core/lib/Drupal/Core/Field/ConfigFieldItemList.php @@ -61,7 +61,7 @@ class ConfigFieldItemList extends FieldItemList implements ConfigFieldItemListIn // 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 07551666053..8e57f7c47f0 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -188,6 +188,14 @@ class FieldDefinition implements FieldDefinitionInterface { 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 3bab0d7f8dc..bdaf247ea1f 100644 --- a/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -53,6 +53,11 @@ use Drupal\Core\Entity\EntityInterface; */ 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 @@ interface FieldDefinitionInterface { /** * 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 @@ interface FieldDefinitionInterface { */ 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 4c78b04b365..612e668e7c0 100644 --- a/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -146,7 +146,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface // 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 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface '#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 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface ); // 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 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface * 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 c89b3469843..2eb3c7d5041 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 @@ class EditAutocompleteTermTest extends WebTestBase { '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 f07a6ee4257..b2879dcd0ce 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 @@ class EntityReferenceAutoCreateTest extends WebTestBase { '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 db6f33924d3..b85380eddc2 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 e5aa0bebae9..ebdc3d77235 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 2f0de84b72a..6d314b2f1a3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -75,11 +75,6 @@ require_once __DIR__ . '/field.deprecated.inc'; * 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 6d1f488f61c..b2f33c133bf 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 6fb8ab7747b..0a8d1a4e002 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 @@ class Field extends ConfigEntityBase implements FieldInterface { 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 65013c0eb72..6d43b630f94 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 @@ class FieldInstance extends ConfigEntityBase implements FieldInstanceInterface { 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 995bc9eab21..0d4d78eaf9c 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\EntityInterface; 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 @@ class Field extends FieldPluginBase { $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 @@ class Field extends FieldPluginBase { // 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 6fe20eb6b14..0f57fcefa20 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 @@ class FormTest extends FieldTestBase { '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 ad2b9586b7e..5da9ec0c90b 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 @@ class NestedFormTest extends FieldTestBase { '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 7f157e2ed81..3bed1b98a38 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 @@ class HandlerFieldFieldTest extends FieldTestBase { '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 @@ class HandlerFieldFieldTest extends FieldTestBase { '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 1f277f51602..4f426ea21a7 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 @@ class FieldEditForm extends FormBase { '#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 e3d6e319ac9..502aef3fe49 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 @@ class ManageFieldsTest extends FieldUiTestBase { // 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 809cc08d845..7ce14b8b3f2 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 @@ class FileWidget extends WidgetBase { // 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 @@ class FileWidget extends WidgetBase { } $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 18bead4afcd..d4e27f562ad 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 @@ class FileFieldValidateTest extends FileFieldTestBase { // 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 22f2b47b99d..322d4452ede 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 @@ class FileItemTest extends FieldUnitTestBase { '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 ebdb1c78c10..ee2581d5442 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 @@ class ImageItemTest extends FieldUnitTestBase { '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 0ee9de29ae1..166f4766902 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 @@ abstract class OptionsWidgetBase extends WidgetBase { // 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 0f157904126..274b5aacafc 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 @@ class TaxonomyTermReferenceRdfaTest extends FieldRdfaTestBase { '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 9d621680a27..f19cff2e99e 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 @@ class TaxonomyTermFieldAttributesTest extends TaxonomyTestBase { '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 7709d64ae5f..1e3dbd3cd4c 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 @@ class MultiFormTest extends AjaxTestBase { '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 163e5df2517..a05e6841a2a 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 @@ class RebuildTest extends WebTestBase { '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 654ea15abaa..e89c531370c 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 @@ class RssTest extends TaxonomyTestBase { '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 1b989bdefdc..df4255650cf 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 @@ class TaxonomyTermReferenceItemTest extends FieldUnitTestBase { '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 9ddb3c47dcb..18e218435bb 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 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase { '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 686b4ebf905..c7abc5c987f 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 @@ class TermIndexTest extends TaxonomyTestBase { '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 @@ class TermIndexTest extends TaxonomyTestBase { '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 d11eefe3c9f..26f04adb6f8 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 @@ class TermTest extends TaxonomyTestBase { '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 fb501e598fb..be4ed537119 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 @@ class TokenReplaceTest extends TaxonomyTestBase { '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 6e7d3932abb..b44e6c514b5 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 @@ abstract class TaxonomyTestBase extends ViewTestBase { '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 34b348b49ec..d952f8c7745 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 @@ class UserRegistrationTest extends WebTestBase { $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 497af62b691..8a046048bbb 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 @@ class TaggedWithTest extends WizardTestBase { '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(