diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index c51d5a1..c021c57 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -44,6 +44,29 @@ public function getFieldDefinition() { } /** + * Returns the array of field settings. + * + * @return array + * The array of settings. + */ + protected function getFieldSettings() { + return $this->getFieldDefinition()->getFieldSettings(); + } + + /** + * Returns the value of a field setting. + * + * @param string $setting_name + * The setting name. + * + * @return mixed + * The setting value. + */ + protected function getFieldSetting($setting_name) { + return $this->getFieldDefinition()->getFieldSetting($setting_name); + } + + /** * Overrides \Drupal\Core\TypedData\TypedData::setValue(). * * @param array|null $values diff --git a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php index c7725d9..d5cce2a 100644 --- a/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php +++ b/core/modules/telephone/lib/Drupal/telephone/Plugin/field/field_type/TelephoneItem.php @@ -81,7 +81,7 @@ public function getConstraints() { 'value' => array( 'Length' => array( 'max' => $max_length, - 'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', array('%name' => $this->getInstance()->label, '@max' => $max_length)), + 'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getFieldLabel(), '@max' => $max_length)), ) ), )); diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php index 1c79cf7..40d3325 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php @@ -67,7 +67,7 @@ public function getConstraints() { $constraint_manager = \Drupal::typedData()->getValidationConstraintManager(); $constraints = parent::getConstraints(); - if ($max_length = $this->getFieldDefinition()->getFieldSetting('max_length')) { + if ($max_length = $this->getFieldSetting('max_length')) { $constraints[] = $constraint_manager->create('ComplexData', array( 'value' => array( 'Length' => array( @@ -86,18 +86,17 @@ public function getConstraints() { */ public function settingsForm(array $form, array &$form_state) { $element = array(); - $field = $this->getInstance()->getField(); $element['max_length'] = array( '#type' => 'number', '#title' => t('Maximum length'), - '#default_value' => $field->settings['max_length'], + '#default_value' => $this->getFieldSetting('max_length'), '#required' => TRUE, '#description' => t('The maximum length of the field in characters.'), '#min' => 1, // @todo: If $has_data, add a validate handler that only allows // max_length to increase. - '#disabled' => $field->hasData(), + '#disabled' => $this->getInstance()->getField()->hasData(), ); return $element; @@ -112,7 +111,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { $element['text_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), - '#default_value' => $this->getInstance()->settings['text_processing'], + '#default_value' => $this->getFieldSetting('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/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index df9cea0..cf41e9d 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -74,7 +74,7 @@ public function prepareCache() { // Where possible, generate the sanitized version of each field early so // that it is cached in the field cache. This avoids the need to look up the // field in the filter cache separately. - $text_processing = $this->getFieldDefinition()->getFieldSetting('text_processing'); + $text_processing = $this->getFieldSetting('text_processing'); if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { $itemBC = $this->getValue(); $langcode = $this->getParent()->getParent()->language()->id; diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php index be86655..9aa06ed 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextLongItem.php @@ -66,7 +66,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { $element['text_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), - '#default_value' => $this->getInstance()->settings['text_processing'], + '#default_value' => $this->getFieldSetting('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/field_type/TextWithSummaryItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php index 7aecf67..71bc17e 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextWithSummaryItem.php @@ -108,11 +108,12 @@ public function isEmpty() { */ public function instanceSettingsForm(array $form, array &$form_state) { $element = array(); + $settings = $this->getFieldSettings(); $element['text_processing'] = array( '#type' => 'radios', '#title' => t('Text processing'), - '#default_value' => $this->getInstance()->settings['text_processing'], + '#default_value' => $settings['text_processing'], '#options' => array( t('Plain text'), t('Filtered text (user selects text format)'), @@ -121,7 +122,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { $element['display_summary'] = array( '#type' => 'checkbox', '#title' => t('Summary input'), - '#default_value' => $this->getInstance()->settings['display_summary'], + '#default_value' => $settings['display_summary'], '#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'), );