Commit 6e381483 authored by webchick's avatar webchick

Issue #1798104 by zuuperman: Fixed Default value widget settings broken by WidgetPlugins.

parent 80505246
......@@ -194,7 +194,7 @@ function _field_info_collate_types_reset() {
*/
function field_behaviors_widget($op, $instance) {
$info = field_info_widget_types($instance['widget']['type']);
return isset($info['behaviors'][$op]) ? $info['behaviors'][$op] : FIELD_BEHAVIOR_DEFAULT;
return isset($info[$op]) ? $info[$op] : FIELD_BEHAVIOR_DEFAULT;
}
/**
......
......@@ -66,7 +66,10 @@ public function getDefinitions() {
$definition['multiple_values'] = $definition['behaviors']['multiple values'];
unset($definition['behaviors']['multiple values']);
}
if (isset($definition['behaviors']['default value'])) {
$definition['default_value'] = $definition['behaviors']['default value'];
unset($definition['behaviors']['default value']);
}
$definitions[$plugin_id] = $definition;
}
}
......
......@@ -23,6 +23,7 @@ class WidgetPluginManager extends PluginManagerBase {
protected $defaults = array(
'settings' => array(),
'multiple_values' => FALSE,
'default_value' => TRUE,
);
/**
......
......@@ -209,6 +209,7 @@ function testInstancePrepare() {
$this->assertIdentical($display['type'], $field_type['default_formatter'], t("Formatter is set for the 'default' view mode"));
$formatter_type = field_info_formatter_types($display['type']);
$this->assertIdentical($display['settings'], $formatter_type['settings'] , t("Formatter settings are set for the 'default' view mode"));
}
/**
......
<?php
/**
* @file
* Definition of Drupal\field_test\Plugin\field\widget\TestFieldWidgetNoDefault.
*/
namespace Drupal\field_test\Plugin\field\widget;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'test_field_widget_no_default' widget.
*
* @Plugin(
* id = "test_field_widget_no_default",
* module = "field_test",
* label = @Translation("Test widget - no default"),
* field_types = {
* "test_field"
* },
* settings = {
* "test_widget_setting_multiple" = "dummy test string"
* },
* default_value = FALSE
* )
*/
class TestFieldWidgetNoDefault extends TestFieldWidget {}
......@@ -1944,7 +1944,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) {
$form['instance']['widget']['settings'] = $additions ? $additions : array('#type' => 'value', '#value' => array());
// Add handling for default value if not provided by any other module.
if (field_behaviors_widget('default value', $instance) == FIELD_BEHAVIOR_DEFAULT && empty($instance['default_value_function'])) {
if (field_behaviors_widget('default_value', $instance) == FIELD_BEHAVIOR_DEFAULT && empty($instance['default_value_function'])) {
$form['instance']['default_value_widget'] = field_ui_default_value_widget($field, $instance, $form, $form_state);
}
......@@ -1968,7 +1968,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) {
// Build the configurable field values.
$description = t('Maximum number of values users can enter for this field.');
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) {
if (field_behaviors_widget('multiple_values', $instance) == FIELD_BEHAVIOR_DEFAULT) {
$description .= '<br/>' . t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like.");
}
$form['field']['cardinality'] = array(
......
......@@ -231,6 +231,13 @@ function testDefaultValue() {
field_info_cache_clear();
$instance = field_info_instance('node', $field_name, $this->type);
$this->assertEqual($instance['default_value'], NULL, 'The default value was correctly saved.');
// Change the widget to TestFieldWidgetNoDefault.
$instance['widget']['type'] = 'test_field_widget_no_default';
field_update_instance($instance);
$this->drupalGet($admin_path);
$this->assertNoFieldById($element_id, '', t('No default value was possible for widget that disables default value.'));
}
/**
......
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