Commit 772849f0 authored by catch's avatar catch

Issue #2060003 by claudiu.cristea, yched: Fixed Wrong precedence in...

Issue #2060003 by claudiu.cristea, yched: Fixed Wrong precedence in Field::getFieldSetting[s]() when setting appears in both field and instance.
parent 66178e04
......@@ -581,7 +581,7 @@ public function getFieldSettings() {
// the default field and instance settings, within $this.
$field_type_info = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type);
$settings = $field_type_info['instance_settings'] + $this->settings + $field_type_info['settings'];
$settings = $this->settings + $field_type_info['settings'] + $field_type_info['instance_settings'];
return $settings;
}
......@@ -594,15 +594,15 @@ public function getFieldSetting($setting_name) {
// We assume here that consecutive array_key_exists() is more efficient than
// calling getFieldSettings() when all we need is a single setting.
if (array_key_exists($setting_name, $field_type_info['instance_settings'])) {
return $field_type_info['instance_settings'][$setting_name];
}
elseif (array_key_exists($setting_name, $this->settings)) {
if (array_key_exists($setting_name, $this->settings)) {
return $this->settings[$setting_name];
}
else {
elseif (array_key_exists($setting_name, $field_type_info['settings'])) {
return $field_type_info['settings'][$setting_name];
}
else {
return $field_type_info['instance_settings'][$setting_name];
}
}
/**
......
......@@ -30,7 +30,7 @@ public static function getInfo() {
/**
* Tests CRUD for fields and fields instances with default images.
*/
function testDefaultImages() {
public function testDefaultImages() {
// Create files to use as the default images.
$files = $this->drupalGetTestFiles('image');
$default_images = array();
......@@ -52,7 +52,22 @@ function testDefaultImages() {
'preview_image_style' => 'medium',
);
$instance = $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings);
$field = field_info_field($field_name);
// The instance default image id should be 2.
$this->assertEqual($instance->getFieldSetting('default_image'), $default_images['instance']->id());
// Also test \Drupal\field\Plugin\Core\Entity\FieldInstance::getFieldSetting().
$instance_field_settings = $instance->getFieldSettings();
$this->assertEqual($instance_field_settings['default_image'], $default_images['instance']->id());
$field = entity_load('field_entity', $field_name);
// The field default image id should be 1.
$this->assertEqual($field->getFieldSetting('default_image'), $default_images['field']->id());
// Also test \Drupal\field\Plugin\Core\Entity\Field::getFieldSettings().
$field_field_settings = $field->getFieldSettings();
$this->assertEqual($field_field_settings['default_image'], $default_images['field']->id());
// Add another instance with another default image to the page content type.
$instance2 = entity_create('field_instance', array(
......
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