Issue #2152825 by plopesc, swentel, Berdir: Rename FieldItemBase::getFieldSetting[s]() to getSetting[s]().

8.0.x
Nathaniel Catchpole 2014-02-13 11:17:25 +00:00
parent 120c40d13c
commit 4bbef0e0c4
19 changed files with 69 additions and 36 deletions

View File

@ -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);
}

View File

@ -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}
*/

View File

@ -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.
*

View File

@ -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();

View File

@ -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'),

View File

@ -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();

View File

@ -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) {

View File

@ -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';
}

View File

@ -113,13 +113,13 @@ class FileItem extends EntityReferenceItem implements ConfigFieldItemInterface {
$element['display_field'] = array(
'#type' => 'checkbox',
'#title' => t('Enable <em>Display</em> 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;

View File

@ -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('', '');

View File

@ -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'),

View File

@ -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'));
}
}

View File

@ -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'])) {

View File

@ -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.'));
}

View File

@ -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'),

View File

@ -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)'),

View File

@ -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') {

View File

@ -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)'),

View File

@ -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',