diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php b/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php index d49251c..06c8645 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/field_type/FileItem.php @@ -117,21 +117,19 @@ public function getPropertyDefinitions() { */ public function settingsForm(array $form, array &$form_state) { $element = array(); - $field = $this->getInstance()->getField(); - $settings = $field->settings; $element['#attached']['library'][] = array('file', 'drupal.file'); $element['display_field'] = array( '#type' => 'checkbox', '#title' => t('Enable Display field'), - '#default_value' => $settings['display_field'], + '#default_value' => $this->getFieldDefinition()->getFieldSetting('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' => $settings['display_default'], + '#default_value' => $this->getFieldDefinition()->getFieldSetting('display_default'), '#description' => t('This setting only has an effect if the display option is enabled.'), '#states' => array( 'visible' => array( @@ -148,9 +146,9 @@ public function settingsForm(array $form, array &$form_state) { '#type' => 'radios', '#title' => t('Upload destination'), '#options' => $scheme_options, - '#default_value' => $settings['uri_scheme'], + '#default_value' => $this->getFieldDefinition()->getFieldSetting('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' => $field->hasData(), + '#disabled' => $this->getInstance()->getField()->hasData(), ); return $element; @@ -161,7 +159,7 @@ public function settingsForm(array $form, array &$form_state) { */ public function instanceSettingsForm(array $form, array &$form_state) { $element = array(); - $settings = $this->getInstance()->settings; + $settings = $this->getFieldDefinition()->getFieldSettings(); $element['file_directory'] = array( '#type' => 'textfield', @@ -258,9 +256,6 @@ public function isEmpty() { * * This function is assigned as an #element_validate callback in * instanceSettingsForm(). - * - * @todo Move directory preparation in FileWidget::massageFormValues() and - * drop this. */ public function validateDirectory($element, &$form_state) { // Strip slashes from the beginning and end of $element['file_directory']. @@ -277,10 +272,6 @@ public function validateDirectory($element, &$form_state) { * This doubles as a convenience clean-up function and a validation routine. * Commas are allowed by the end-user, but ultimately the value will be stored * as a space-separated list for compatibility with file_validate_extensions(). - * - * @todo - * - Move extensions preparation in FileWidget::massageFormValues(). - * - Move validation in constrains. */ public function validateExtensions($element, &$form_state) { if (!empty($element['#value'])) { @@ -304,8 +295,6 @@ public function validateExtensions($element, &$form_state) { * * This function is assigned as an #element_validate callback in * finstanceSettingsForm(). - * - * @todo Move validation in constrains. */ public function validateMaxFilesize($element, &$form_state) { if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) { diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php index 9076358..92275e6 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/field_type/ImageItem.php @@ -141,8 +141,6 @@ public function getPropertyDefinitions() { */ public function settingsForm(array $form, array &$form_state) { $element = array(); - $field = $this->getInstance()->getField(); - $settings = $field->settings; $scheme_options = array(); foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { @@ -152,18 +150,19 @@ public function settingsForm(array $form, array &$form_state) { '#type' => 'radios', '#title' => t('Upload destination'), '#options' => $scheme_options, - '#default_value' => $settings['uri_scheme'], + '#default_value' => $this->getFieldDefinition()->getFieldSetting('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.'), ); // When the user sets the scheme on the UI, even for the first time, it's // updating a field because fields are created on the "Manage fields" // page. + $default_image = $this->getFieldDefinition()->getFieldSetting('default_image'); $element['default_image'] = array( '#title' => t('Default image'), '#type' => 'managed_file', '#description' => t('If no image is uploaded, this image will be shown on display.'), - '#default_value' => empty($settings['default_image']) ? array() : array($settings['default_image']), - '#upload_location' => $settings['uri_scheme'] . '://default_images/', + '#default_value' => empty($default_image) ? array() : array($default_image), + '#upload_location' => $this->getFieldDefinition()->getFieldSetting('uri_scheme') . '://default_images/', ); @@ -176,8 +175,7 @@ public function settingsForm(array $form, array &$form_state) { public function instanceSettingsForm(array $form, array &$form_state) { // Get base form from FileItem::instanceSettingsForm(). $element = parent::instanceSettingsForm($form, $form_state); - $settings = $this->getInstance()->settings; - $field = $this->getInstance()->getField(); + $settings = $this->getFieldDefinition()->getFieldSettings(); // Add maximum and minimum resolution settings. $max_resolution = explode('x', $settings['max_resolution']) + array('', ''); @@ -281,7 +279,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { '#type' => 'managed_file', '#description' => t("If no image is uploaded, this image will be shown on display and will override the field's default image."), '#default_value' => empty($settings['default_image']) ? array() : array($settings['default_image']), - '#upload_location' => $field->settings['uri_scheme'] . '://default_images/', + '#upload_location' => $settings['uri_scheme'] . '://default_images/', ); return $element; @@ -337,10 +335,6 @@ public function isEmpty() { /** * Element validate function for resolution fields. - * - * @todo Split this between: - * - Constrains for validation. - * - Move resolution preparing into ImageWidget::massageFormValues(). */ public function validateResolution($element, &$form_state) { if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) {