Commit 4bbef0e0 authored by catch's avatar catch

Issue #2152825 by plopesc, swentel, Berdir: Rename...

Issue #2152825 by plopesc, swentel, Berdir: Rename FieldItemBase::getFieldSetting[s]() to getSetting[s]().
parent 120c40d1
......@@ -64,7 +64,7 @@ public function getFieldDefinition() {
* @return array
* The array of settings.
*/
protected function getFieldSettings() {
protected function getSettings() {
return $this->getFieldDefinition()->getSettings();
}
......@@ -77,7 +77,7 @@ protected function getFieldSettings() {
* @return mixed
* The setting value.
*/
protected function getFieldSetting($setting_name) {
protected function getSetting($setting_name) {
return $this->getFieldDefinition()->getSetting($setting_name);
}
......
......@@ -78,6 +78,20 @@ public function getFieldDefinition() {
return $this->definition;
}
/**
* {@inheritdoc}
*/
public function getSettings() {
return $this->definition->getSettings();
}
/**
* {@inheritdoc}
*/
public function getSetting($setting_name) {
return $this->definition->getSetting($setting_name);
}
/**
* {@inheritdoc}
*/
......
......@@ -60,6 +60,25 @@ public function getLangcode();
*/
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.
*
......
......@@ -92,7 +92,7 @@ public static function schema(FieldDefinitionInterface $field_definition) {
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();
......
......@@ -94,7 +94,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
'#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'),
......
......@@ -158,7 +158,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
'#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 @@ public function instanceSettingsForm(array $form, array &$form_state) {
$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();
......
......@@ -33,7 +33,7 @@ protected function getDefaultValue() {
}
}
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 @@ public function defaultValuesFormSubmit(array $element, array &$form, array &$fo
$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) {
......
......@@ -79,7 +79,7 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
$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 @@ public function instanceSettingsForm(array $form, array &$form_state) {
$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 @@ public function getCacheData() {
// 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';
}
......
......@@ -113,13 +113,13 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
$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 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
'#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 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
*/
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 @@ public static function validateMaxFilesize($element, &$form_state) {
* @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 @@ public function getUploadLocation($data = array()) {
*/
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 @@ public function getUploadValidators() {
* 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;
......
......@@ -175,7 +175,7 @@ public function instanceSettingsForm(array $form, array &$form_state) {
// 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('', '');
......
......@@ -89,7 +89,7 @@ public function instanceSettingsForm(array $form, array &$form_state) {
$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'),
......
......@@ -66,7 +66,7 @@ public static function schema(FieldDefinitionInterface $field_definition) {
*/
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 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
* {@inheritdoc}
*/
public function preSave() {
$this->value = round($this->value, $this->getFieldSetting('scale'));
$this->value = round($this->value, $this->getSetting('scale'));
}
}
......@@ -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 @@ public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$settings = $this->getFieldSettings();
$settings = $this->getSettings();
$label = $this->getFieldDefinition()->getLabel();
if (!empty($settings['min'])) {
......
......@@ -71,8 +71,8 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
// 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 @@ public function validateAllowedValues($element, &$form_state) {
// 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.'));
}
......
......@@ -68,12 +68,12 @@ public function getSettableValues(AccountInterface $account = NULL) {
* {@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 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
$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'),
......
......@@ -58,7 +58,7 @@ public function getConstraints() {
$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 @@ public function settingsForm(array $form, array &$form_state, $has_data) {
$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 @@ public function instanceSettingsForm(array $form, array &$form_state) {
$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)'),
......
......@@ -71,7 +71,7 @@ public function getCacheData() {
// 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') {
......
......@@ -57,7 +57,7 @@ public function instanceSettingsForm(array $form, array &$form_state) {
$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)'),
......
......@@ -95,7 +95,7 @@ public function isEmpty() {
*/
public function instanceSettingsForm(array $form, array &$form_state) {
$element = array();
$settings = $this->getFieldSettings();
$settings = $this->getSettings();
$element['text_processing'] = array(
'#type' => 'radios',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment