diff --git a/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php b/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php index ef79967..3effe65 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php @@ -188,6 +188,14 @@ public function isFieldRequired() { } /** + * {@inheritdoc} + */ + public function isFieldMultiple() { + $cardinality = $this->getFieldCardinality(); + return ($cardinality == static::CARDINALITY_UNLIMITED) || ($cardinality > 1); + } + + /** * Sets whether the field is required. * * @param bool $required diff --git a/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php index b8dc354..26a9c2c 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldDefinitionInterface.php @@ -54,6 +54,11 @@ interface FieldDefinitionInterface { /** + * Value indicating a field accepts an unlimited number of values. + */ + const CARDINALITY_UNLIMITED = -1; + + /** * Returns the machine name of the field. * * This defines how the field data is accessed from the entity. For example, @@ -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. @@ -170,6 +176,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. * * @param \Drupal\Core\Entity\EntityInterface $entity diff --git a/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php index 07cf115..5497efb 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/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditAutocompleteTermTest.php index c89b346..7e63021 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\Entity\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 f07a6ee..a18e127 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\Entity\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.form.inc b/core/modules/field/field.form.inc index 6f99192..f7bcd6b 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\Entity\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'] > 1 || $element['#cardinality'] == FieldDefinitionInterface::CARDINALITY_UNLIMITED) { $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 84fd041..0ec9d1d 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -76,11 +76,6 @@ */ /** - * Value for field API indicating a field accepts an unlimited number of values. - */ -const FIELD_CARDINALITY_UNLIMITED = -1; - -/** * Implements hook_help(). */ function field_help($path, $arg) { diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index aecc48c..d0889af 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 4496e16..eca7a13 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 */ @@ -600,6 +601,14 @@ public function isFieldRequired() { /** * {@inheritdoc} */ + public function isFieldMultiple() { + $cardinality = $this->getFieldCardinality(); + return ($cardinality == static::CARDINALITY_UNLIMITED) || ($cardinality > 1); + } + + /** + * {@inheritdoc} + */ public function getFieldDefaultValue(EntityInterface $entity) { } /** diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php index dea4c95..9dc1cba 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php @@ -587,6 +587,13 @@ public function isFieldRequired() { /** * {@inheritdoc} */ + public function isFieldMultiple() { + return $this->field->isFieldMultiple(); + } + + /** + * {@inheritdoc} + */ public function getFieldDefaultValue(EntityInterface $entity) { if (!empty($this->default_value_function)) { $function = $this->default_value_function; diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemList.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemList.php index 32bea80..f78dc56 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemList.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemList.php @@ -7,8 +7,9 @@ namespace Drupal\field\Plugin\Type\FieldType; -use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldItemList; +use Drupal\Core\TypedData\TypedDataInterface; use Drupal\field\Field as FieldAPI; /** @@ -54,7 +55,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/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index 564ec20..f04b439 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -150,7 +150,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; @@ -213,7 +213,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', @@ -408,9 +408,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/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 9779733..b0ccc85 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 @@ -7,6 +7,7 @@ namespace Drupal\field\Plugin\views\field; +use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\FieldableDatabaseStorageController; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; @@ -130,7 +131,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 @@ -487,7 +488,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 f9b37d5..73b1e59 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\Entity\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 ad2b958..dd8e164 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\Entity\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 7f157e2..6cf7c88 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\Entity\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 ebbd84c..d01be78 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 1a8f65e..6c5931b 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\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; /** @@ -199,12 +200,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/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index b0ed274..486b71e 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -7,6 +7,7 @@ namespace Drupal\file\Plugin\field\widget; +use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\field\Plugin\Type\Widget\WidgetBase; use Drupal\Core\Entity\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 18bead4..24fa44b 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\Entity\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 31396ca..764238b 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\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldItemInterface; use Drupal\Core\Entity\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 4fd70f7..0a26e6a 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\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldItemListInterface; use Drupal\Core\Entity\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/widget/OptionsWidgetBase.php b/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php index 2301789..e5279a3 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/field/widget/OptionsWidgetBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/field/widget/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 38ee919..df377f2 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\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; /** @@ -62,7 +63,7 @@ public function setUp() { 'name' => $this->fieldName, 'entity_type' => 'entity_test_render', '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 9d62168..078681d 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\Entity\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 7709d64..884a191 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\Entity\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 163e5df..9b1d860 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\Entity\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 654ea15..5706120 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\Entity\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 6c5f1ea..76d9eba 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php @@ -8,6 +8,7 @@ namespace Drupal\taxonomy\Tests; use Drupal\Core\Language\Language; +use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Field\FieldItemListInterface; use Drupal\Core\Entity\Field\FieldItemInterface; 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 9ddb3c4..7797d30 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\Entity\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 686b4eb..785b922 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\Entity\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 d11eefe..6acc860 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\Entity\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 fb501e5..ce0bf7c 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\Entity\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 6e7d393..632f48c 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\Entity\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 34b348b..b483714 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\Entity\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 497af62..96a4280 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\Entity\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(