diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php index b5b0f3f457b..125b964c94c 100644 --- a/core/lib/Drupal/Core/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Field/FieldItemBase.php @@ -64,7 +64,7 @@ abstract class FieldItemBase extends Map implements FieldItemInterface { * @return array * The array of settings. */ - protected function getFieldSettings() { + protected function getSettings() { return $this->getFieldDefinition()->getSettings(); } @@ -77,7 +77,7 @@ abstract class FieldItemBase extends Map implements FieldItemInterface { * @return mixed * The setting value. */ - protected function getFieldSetting($setting_name) { + protected function getSetting($setting_name) { return $this->getFieldDefinition()->getSetting($setting_name); } diff --git a/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php index 6a48db4d957..8afca40cd32 100644 --- a/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -78,6 +78,20 @@ class FieldItemList extends ItemList implements FieldItemListInterface { return $this->definition; } + /** + * {@inheritdoc} + */ + public function getSettings() { + return $this->definition->getSettings(); + } + + /** + * {@inheritdoc} + */ + public function getSetting($setting_name) { + return $this->definition->getSetting($setting_name); + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Field/FieldItemListInterface.php b/core/lib/Drupal/Core/Field/FieldItemListInterface.php index 79909485077..0af22451839 100644 --- a/core/lib/Drupal/Core/Field/FieldItemListInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemListInterface.php @@ -60,6 +60,25 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface { */ public function getFieldDefinition(); + /** + * Returns the array of field settings. + * + * @return array + * An array of key/value pairs. + */ + public function getSettings(); + + /** + * Returns the value of a given field setting. + * + * @param string $setting_name + * The setting name. + * + * @return mixed + * The setting value. + */ + public function getSetting($setting_name); + /** * Contains the default access logic of this field. * diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php index 4380baa88a9..a43e3387bc0 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldType/CommentItem.php @@ -92,7 +92,7 @@ class CommentItem extends ConfigFieldItemBase { public function instanceSettingsForm(array $form, array &$form_state) { $element = array(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $entity_type = $this->getEntity()->getEntityTypeId(); $field_name = $this->getFieldDefinition()->getName(); diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php index c5a9cf72e9a..43aa5501533 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/Field/FieldType/DateTimeItem.php @@ -94,7 +94,7 @@ class DateTimeItem extends ConfigFieldItemBase implements PrepareCacheInterface '#type' => 'select', '#title' => t('Date type'), '#description' => t('Choose the type of date to create.'), - '#default_value' => $this->getFieldSetting('datetime_type'), + '#default_value' => $this->getSetting('datetime_type'), '#options' => array( static::DATETIME_TYPE_DATETIME => t('Date and time'), static::DATETIME_TYPE_DATE => t('Date only'), diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php index c350955b2c1..f2eb69927b9 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/ConfigurableEntityReferenceItem.php @@ -158,7 +158,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements Con '#type' => 'select', '#title' => t('Type of item to reference'), '#options' => \Drupal::entityManager()->getEntityTypeLabels(), - '#default_value' => $this->getFieldSetting('target_type'), + '#default_value' => $this->getSetting('target_type'), '#required' => TRUE, '#disabled' => $has_data, '#size' => 1, @@ -174,7 +174,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements Con $instance = $form_state['instance']; // Get all selection plugins for this entity type. - $selection_plugins = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionGroups($this->getFieldSetting('target_type')); + $selection_plugins = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionGroups($this->getSetting('target_type')); $handler_groups = array_keys($selection_plugins); $handlers = \Drupal::service('plugin.manager.entity_reference.selection')->getDefinitions(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldType/ConfigurableEntityReferenceFieldItemList.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldType/ConfigurableEntityReferenceFieldItemList.php index 9623c436e6e..c4e0775d6aa 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldType/ConfigurableEntityReferenceFieldItemList.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldType/ConfigurableEntityReferenceFieldItemList.php @@ -33,7 +33,7 @@ class ConfigurableEntityReferenceFieldItemList extends ConfigFieldItemList { } } if ($uuids) { - $target_type = $this->getFieldDefinition()->getSetting('target_type'); + $target_type = $this->getSetting('target_type'); $entity_ids = \Drupal::entityQuery($target_type) ->condition('uuid', $uuids, 'IN') ->execute(); @@ -80,7 +80,7 @@ class ConfigurableEntityReferenceFieldItemList extends ConfigFieldItemList { $ids[] = $properties['target_id']; } $entities = \Drupal::entityManager() - ->getStorageController($this->getFieldDefinition()->getSetting('target_type')) + ->getStorageController($this->getSetting('target_type')) ->loadMultiple($ids); foreach ($default_value as $delta => $properties) { diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php index 2157658e0a0..be3955f3254 100644 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Field/FieldType/TestItem.php @@ -79,7 +79,7 @@ class TestItem extends ConfigFieldItemBase implements PrepareCacheInterface { $form['test_field_setting'] = array( '#type' => 'textfield', '#title' => t('Field test field setting'), - '#default_value' => $this->getFieldSetting('test_field_setting'), + '#default_value' => $this->getSetting('test_field_setting'), '#required' => FALSE, '#description' => t('A dummy form element to simulate field setting.'), ); @@ -94,7 +94,7 @@ class TestItem extends ConfigFieldItemBase implements PrepareCacheInterface { $form['test_instance_setting'] = array( '#type' => 'textfield', '#title' => t('Field test field instance setting'), - '#default_value' => $this->getFieldSetting('test_instance_setting'), + '#default_value' => $this->getSetting('test_instance_setting'), '#required' => FALSE, '#description' => t('A dummy form element to simulate field instance setting.'), ); @@ -109,7 +109,7 @@ class TestItem extends ConfigFieldItemBase implements PrepareCacheInterface { // To keep the test non-intrusive, only act for instances with the // 'test_cached_data' setting explicitly set to TRUE. Also don't add // anything on empty values. - if ($this->getFieldSetting('test_cached_data') && !$this->isEmpty()) { + if ($this->getSetting('test_cached_data') && !$this->isEmpty()) { // Set the additional value so that getValue() will return it. $this->additional_key = 'additional_value'; } diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php index 886be529608..0be4a99344c 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldType/FileItem.php @@ -113,13 +113,13 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface { $element['display_field'] = array( '#type' => 'checkbox', '#title' => t('Enable Display field'), - '#default_value' => $this->getFieldSetting('display_field'), + '#default_value' => $this->getSetting('display_field'), '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'), ); $element['display_default'] = array( '#type' => 'checkbox', '#title' => t('Files displayed by default'), - '#default_value' => $this->getFieldSetting('display_default'), + '#default_value' => $this->getSetting('display_default'), '#description' => t('This setting only has an effect if the display option is enabled.'), '#states' => array( 'visible' => array( @@ -136,7 +136,7 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface { '#type' => 'radios', '#title' => t('Upload destination'), '#options' => $scheme_options, - '#default_value' => $this->getFieldSetting('uri_scheme'), + '#default_value' => $this->getSetting('uri_scheme'), '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), '#disabled' => $has_data, ); @@ -149,7 +149,7 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface { */ public function instanceSettingsForm(array $form, array &$form_state) { $element = array(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $element['file_directory'] = array( '#type' => 'textfield', @@ -263,7 +263,7 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface { * @see token_replace() */ public function getUploadLocation($data = array()) { - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $destination = trim($settings['file_directory'], '/'); // Replace tokens. @@ -281,7 +281,7 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface { */ public function getUploadValidators() { $validators = array(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); // Cap the upload size according to the PHP limit. $max_filesize = parse_size(file_upload_max_size()); @@ -307,7 +307,7 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface { * TRUE if the item should be displayed, FALSE if not. */ public function isDisplayed() { - if ($this->getFieldSetting('display_field')) { + if ($this->getSetting('display_field')) { return (bool) $this->display; } return TRUE; diff --git a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php index 849cec8eb38..09987f2041c 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldType/ImageItem.php @@ -175,7 +175,7 @@ class ImageItem extends FileItem { // Get base form from FileItem::instanceSettingsForm(). $element = parent::instanceSettingsForm($form, $form_state); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); // Add maximum and minimum resolution settings. $max_resolution = explode('x', $settings['max_resolution']) + array('', ''); diff --git a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php index eb9c2fc1f51..bc285947a64 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php @@ -89,7 +89,7 @@ class LinkItem extends ConfigFieldItemBase { $element['title'] = array( '#type' => 'radios', '#title' => t('Allow link text'), - '#default_value' => $this->getFieldSetting('title'), + '#default_value' => $this->getSetting('title'), '#options' => array( DRUPAL_DISABLED => t('Disabled'), DRUPAL_OPTIONAL => t('Optional'), diff --git a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php index 3bf223e895f..42588e85007 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php +++ b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/DecimalItem.php @@ -66,7 +66,7 @@ class DecimalItem extends NumberItemBase { */ public function settingsForm(array $form, array &$form_state, $has_data) { $element = array(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $element['precision'] = array( '#type' => 'select', @@ -92,7 +92,7 @@ class DecimalItem extends NumberItemBase { * {@inheritdoc} */ public function preSave() { - $this->value = round($this->value, $this->getFieldSetting('scale')); + $this->value = round($this->value, $this->getSetting('scale')); } } diff --git a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/NumberItemBase.php b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/NumberItemBase.php index e8630be35f6..22f2d595c00 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/NumberItemBase.php +++ b/core/modules/number/lib/Drupal/number/Plugin/Field/FieldType/NumberItemBase.php @@ -26,7 +26,7 @@ abstract class NumberItemBase extends ConfigFieldItemBase { */ public function instanceSettingsForm(array $form, array &$form_state) { $element = array(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $element['min'] = array( '#type' => 'textfield', @@ -77,7 +77,7 @@ abstract class NumberItemBase extends ConfigFieldItemBase { $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $label = $this->getFieldDefinition()->getLabel(); if (!empty($settings['min'])) { diff --git a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php index bd89bb62b51..6e7416b0873 100644 --- a/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php +++ b/core/modules/options/lib/Drupal/options/Plugin/Field/FieldType/ListItemBase.php @@ -71,8 +71,8 @@ abstract class ListItemBase extends ConfigFieldItemBase implements AllowedValues // https://drupal.org/node/2169983. $field_type = $this->getFieldDefinition()->getType(); - $allowed_values = $this->getFieldSetting('allowed_values'); - $allowed_values_function = $this->getFieldSetting('allowed_values_function'); + $allowed_values = $this->getSetting('allowed_values'); + $allowed_values_function = $this->getSetting('allowed_values_function'); if (in_array($field_type, array('list_integer', 'list_float', 'list_text'))) { $element['allowed_values'] = array( @@ -213,7 +213,7 @@ abstract class ListItemBase extends ConfigFieldItemBase implements AllowedValues // Prevent removing values currently in use. if ($has_data) { - $lost_keys = array_diff(array_keys($this->getFieldSetting('allowed_values')), array_keys($values)); + $lost_keys = array_diff(array_keys($this->getSetting('allowed_values')), array_keys($values)); if (_options_values_in_use($this->getEntity()->getEntityTypeId(), $this->getFieldDefinition()->getName(), $lost_keys)) { \Drupal::formBuilder()->setError($element, $form_state, t('Allowed values list: some values are being removed while currently in use.')); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php index e183e05f601..27335152afc 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceItem.php @@ -68,12 +68,12 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements ConfigFie * {@inheritdoc} */ public function getSettableOptions(AccountInterface $account = NULL) { - if ($callback = $this->getFieldSetting('options_list_callback')) { + if ($callback = $this->getSetting('options_list_callback')) { return call_user_func_array($callback, array($this->getFieldDefinition(), $this->getEntity())); } else { $options = array(); - foreach ($this->getFieldSetting('allowed_values') as $tree) { + foreach ($this->getSetting('allowed_values') as $tree) { if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) { foreach ($terms as $term) { @@ -131,7 +131,7 @@ class TaxonomyTermReferenceItem extends EntityReferenceItem implements ConfigFie $element = array(); $element['#tree'] = TRUE; - foreach ($this->getFieldSetting('allowed_values') as $delta => $tree) { + foreach ($this->getSetting('allowed_values') as $delta => $tree) { $element['allowed_values'][$delta]['vocabulary'] = array( '#type' => 'select', '#title' => t('Vocabulary'), diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php index 9157ee8c07e..93bd9491035 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItem.php @@ -58,7 +58,7 @@ class TextItem extends TextItemBase { $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - if ($max_length = $this->getFieldSetting('max_length')) { + if ($max_length = $this->getSetting('max_length')) { $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( 'Length' => array( @@ -81,7 +81,7 @@ class TextItem extends TextItemBase { $element['max_length'] = array( '#type' => 'number', '#title' => t('Maximum length'), - '#default_value' => $this->getFieldSetting('max_length'), + '#default_value' => $this->getSetting('max_length'), '#required' => TRUE, '#description' => t('The maximum length of the field in characters.'), '#min' => 1, @@ -100,7 +100,7 @@ class TextItem extends TextItemBase { $element['text_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), - '#default_value' => $this->getFieldSetting('text_processing'), + '#default_value' => $this->getSetting('text_processing'), '#options' => array( t('Plain text'), t('Filtered text (user selects text format)'), diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php index 90d86c22d76..158c4162927 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php @@ -71,7 +71,7 @@ abstract class TextItemBase extends ConfigFieldItemBase implements PrepareCacheI // textual property (e.g., 'value', 'summary') within this field item early // so that it is cached in the field cache. This avoids the need to look up // the sanitized value in the filter cache separately. - $text_processing = $this->getFieldSetting('text_processing'); + $text_processing = $this->getSetting('text_processing'); if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { foreach ($this->getPropertyDefinitions() as $property => $definition) { if ($definition->getClass() == '\Drupal\text\TextProcessed') { diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php index 7e378fc6481..934d11f38a1 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextLongItem.php @@ -57,7 +57,7 @@ class TextLongItem extends TextItemBase { $element['text_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), - '#default_value' => $this->getFieldSetting('text_processing'), + '#default_value' => $this->getSetting('text_processing'), '#options' => array( t('Plain text'), t('Filtered text (user selects text format)'), diff --git a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php index 36df9508c17..39425107022 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextWithSummaryItem.php @@ -95,7 +95,7 @@ class TextWithSummaryItem extends TextItemBase { */ public function instanceSettingsForm(array $form, array &$form_state) { $element = array(); - $settings = $this->getFieldSettings(); + $settings = $this->getSettings(); $element['text_processing'] = array( '#type' => 'radios',