Commit add6d63d authored by Dries's avatar Dries
Browse files

- Patch #940668 by yched: Fixed 'Manage display' : Formatter change not reflected on settings.

parent b04836c8
......@@ -257,6 +257,61 @@ function field_test_field_formatter_info() {
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function field_test_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
// The name of the setting depends on the formatter type.
$map = array(
'field_test_default' => 'test_formatter_setting',
'field_test_multiple' => 'test_formatter_setting_multiple',
'field_test_with_prepare_view' => 'test_formatter_setting_additional',
);
if (isset($map[$display['type']])) {
$name = $map[$display['type']];
$element[$name] = array(
'#title' => t('Setting'),
'#type' => 'textfield',
'#size' => 20,
'#default_value' => $settings[$name],
'#required' => TRUE,
);
}
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function field_test_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = '';
// The name of the setting depends on the formatter type.
$map = array(
'field_test_default' => 'test_formatter_setting',
'field_test_multiple' => 'test_formatter_setting_multiple',
'field_test_with_prepare_view' => 'test_formatter_setting_additional',
);
if (isset($map[$display['type']])) {
$name = $map[$display['type']];
$summary = t('@setting: @value', array('@setting' => $name, '@value' => $settings[$name]));
}
return $summary;
}
/**
* Implements hook_field_formatter_prepare_view().
*/
......
......@@ -175,12 +175,10 @@ function field_ui_table_pre_render($elements) {
$elements['#regions'][$region_name]['rows_order'] = array_reduce($trees[$region_name], '_field_ui_reduce_order');
}
drupal_add_js(array('fieldUIRowsData' => $js_settings), 'setting');
// @todo : use #attached instead when http://drupal.org/node/561858 is fixed.
// $elements['#attached']['js'][] = array(
// 'type' => 'setting',
// 'data' => array('fieldRowsData' => $js_settings),
// );
$elements['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('fieldUIRowsData' => $js_settings),
);
return $elements;
}
......@@ -956,7 +954,7 @@ function field_ui_display_overview_form($form, &$form_state, $entity_type, $bund
if ($form_state['formatter_settings_edit'] == $name) {
// We are currently editing this field's formatter settings. Display the
// settings form and submit buttons.
$table[$name]['settings_edit_form'] = array();
$table[$name]['format']['settings_edit_form'] = array();
$settings_form = array();
$function = $formatter['module'] . '_field_formatter_settings_form';
......@@ -1111,9 +1109,6 @@ function field_ui_display_overview_form($form, &$form_state, $entity_type, $bund
'#type' => 'submit',
'#value' => t('Refresh'),
'#op' => 'refresh_table',
// Do not check errors, but make sure we get the values of the
// 'refresh_rows' input.
'#limit_validation_errors' => array(array('refresh_rows')),
'#submit' => array('field_ui_display_overview_multistep_submit'),
'#ajax' => array(
'callback' => 'field_ui_display_overview_multistep_js',
......@@ -1132,11 +1127,8 @@ function field_ui_display_overview_form($form, &$form_state, $entity_type, $bund
$form['#attached']['css'][] = drupal_get_path('module', 'field_ui') . '/field_ui.css';
// Add tabledrag behavior.
drupal_add_tabledrag('field-display-overview', 'order', 'sibling', 'field-weight');
drupal_add_tabledrag('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
// @todo : use #attached instead when http://drupal.org/node/561858 is fixed.
// $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'order', 'sibling', 'field-weight');
// $form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
$form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'order', 'sibling', 'field-weight');
$form['#attached']['drupal_add_tabledrag'][] = array('field-display-overview', 'match', 'parent', 'field-parent', 'field-parent', 'field-name');
return $form;
}
......
......@@ -7,19 +7,13 @@
*/
/**
* Field UI tests.
* Helper class for Field UI test classes.
*/
class FieldUITestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Field UI tests',
'description' => 'Test the field UI functionality.',
'group' => 'Field UI',
);
}
function setUp() {
parent::setUp('field_test');
function setUp($modules = array()) {
array_unshift($modules, 'field_test');
parent::setUp($modules);
// Create test user.
$admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer taxonomy'));
......@@ -31,6 +25,119 @@ class FieldUITestCase extends DrupalWebTestCase {
$this->type = $type->type;
// Store a valid URL name, with hyphens instead of underscores.
$this->hyphen_type = str_replace('_', '-', $this->type);
}
/**
* Create a new field through the Field UI.
*
* @param $bundle_path
* Path of the 'Manage fields' page for the bundle.
* @param $initial_edit
* $edit parameter for drupalPost() on the first step ('Manage fields'
* screen).
* @param $field_edit
* $edit parameter for drupalPost() on the second step ('Field settings'
* form).
* @param $instance_edit
* $edit parameter for drupalPost() on the third step ('Instance settings'
* form).
*/
function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
// Use 'test_field' field type by default.
$initial_edit += array(
'fields[_add_new_field][type]' => 'test_field',
'fields[_add_new_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['fields[_add_new_field][label]'];
$field_name = $initial_edit['fields[_add_new_field][field_name]'];
// First step : 'Add new field' on the 'Manage fields' page.
$this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
$this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), t('Field settings page was displayed.'));
// Second step : 'Field settings' form.
$this->drupalPost(NULL, $field_edit, t('Save field settings'));
$this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), t('Redirected to instance and widget settings page.'));
// Third step : 'Instance settings' form.
$this->drupalPost(NULL, $instance_edit, t('Save settings'));
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}
/**
* Add an existing field through the Field UI.
*
* @param $bundle_path
* Path of the 'Manage fields' page for the bundle.
* @param $initial_edit
* $edit parameter for drupalPost() on the first step ('Manage fields'
* screen).
* @param $instance_edit
* $edit parameter for drupalPost() on the second step ('Instance settings'
* form).
*/
function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {
// Use 'test_field_widget' by default.
$initial_edit += array(
'fields[_add_existing_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['fields[_add_existing_field][label]'];
$field_name = $initial_edit['fields[_add_existing_field][field_name]'];
// First step : 'Add existing field' on the 'Manage fields' page.
$this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
// Second step : 'Instance settings' form.
$this->drupalPost(NULL, $instance_edit, t('Save settings'));
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}
/**
* Delete a field instance through the Field UI.
*
* @param $bundle_path
* Path of the 'Manage fields' page for the bundle.
* @param $field_name
* The name of the field.
* @param $label
* The label of the field.
* @param $bundle_label
* The label of the bundle.
*/
function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) {
// Display confirmation form.
$this->drupalGet("$bundle_path/fields/$field_name/delete");
$this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), t('Delete confirmation was found.'));
// Submit confirmation form.
$this->drupalPost(NULL, array(), t('Delete'));
$this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), t('Delete message was found.'));
// Check that the field does not appear in the overview form.
$this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, t('Field does not appear in the overview page.'));
}
}
/**
* Field UI tests for the 'Manage fields' screen.
*/
class FieldUIManageFieldsTestCase extends FieldUITestCase {
public static function getInfo() {
return array(
'name' => 'Manage fields',
'description' => 'Test the Field UI "Manage fields" screen.',
'group' => 'Field UI',
);
}
function setUp() {
parent::setUp();
// Create random field name.
$this->field_label = $this->randomName(8);
......@@ -298,103 +405,69 @@ class FieldUITestCase extends DrupalWebTestCase {
$this->drupalGet($bundle_path);
$this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), t("The 'add existing field' select respects field types 'no_ui' property."));
}
}
/**
* Create a new field through the Field UI.
*
* @param $bundle_path
* Path of the 'Manage fields' page for the bundle.
* @param $initial_edit
* $edit parameter for drupalPost() on the first step ('Manage fields'
* screen).
* @param $field_edit
* $edit parameter for drupalPost() on the first step ('Field settings'
* form).
* @param $instance_edit
* $edit parameter for drupalPost() on the second step ('Instance settings'
* form).
*/
function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
// Use 'test_field' field type by default.
$initial_edit += array(
'fields[_add_new_field][type]' => 'test_field',
'fields[_add_new_field][widget_type]' => 'test_field_widget',
/**
* Field UI tests for the 'Manage display' screens.
*/
class FieldUIManageDisplayTestCase extends FieldUITestCase {
public static function getInfo() {
return array(
'name' => 'Manage display',
'description' => 'Test the Field UI "Manage display" screens.',
'group' => 'Field UI',
);
$label = $initial_edit['fields[_add_new_field][label]'];
$field_name = $initial_edit['fields[_add_new_field][field_name]'];
// First step : 'Add new field' on the 'Manage fields' page.
$this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
$this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), t('Field settings page was displayed.'));
// Second step : 'Field settings' form.
$this->drupalPost(NULL, $field_edit, t('Save field settings'));
$this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), t('Redirected to instance and widget settings page.'));
// Assert the field settings are correct.
$this->assertFieldSettings($this->type, $this->field_name);
// Third step : 'Instance settings' form.
$this->drupalPost(NULL, $instance_edit, t('Save settings'));
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
}
/**
* Add an existing field through the Field UI.
*
* @param $bundle_path
* Path of the 'Manage fields' page for the bundle.
* @param $initial_edit
* $edit parameter for drupalPost() on the first step ('Manage fields'
* screen).
* @param $instance_edit
* $edit parameter for drupalPost() on the second step ('Instance settings'
* form).
*/
function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {
// Use 'test_field_widget' by default.
$initial_edit += array(
'fields[_add_existing_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['fields[_add_existing_field][label]'];
$field_name = $initial_edit['fields[_add_existing_field][field_name]'];
// First step : 'Add existing field' on the 'Manage fields' page.
$this->drupalPost("$bundle_path/fields", $initial_edit, t('Save'));
// Second step : 'Instance settings' form.
$this->drupalPost(NULL, $instance_edit, t('Save settings'));
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), t('Redirected to "Manage fields" page.'));
// Check that the field appears in the overview form.
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, t('Field was created and appears in the overview page.'));
function setUp() {
parent::setUp(array('search'));
}
/**
* Delete a field instance through the Field UI.
*
* @param $bundle_path
* Path of the 'Manage fields' page for the bundle.
* @param $field_name
* The name of the field.
* @param $label
* The label of the field.
* @param $bundle_label
* The label of the bundle.
* Test formatter formatter settings.
*/
function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) {
// Display confirmation form.
$this->drupalGet("$bundle_path/fields/$field_name/delete");
$this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), t('Delete confirmation was found.'));
function testFormatterUI() {
$manage_fields = 'admin/structure/types/manage/' . $this->hyphen_type;
$manage_display = $manage_fields . '/display';
// Submit confirmation form.
$this->drupalPost(NULL, array(), t('Delete'));
$this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), t('Delete message was found.'));
// Create a field, and a node with some data for the field.
$edit = array(
'fields[_add_new_field][label]' => 'Test field',
'fields[_add_new_field][field_name]' => 'field_test',
);
$this->fieldUIAddNewField($manage_fields, $edit);
// Check that the field doesn not appear in the overview form
$this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, t('Field does not appear in the overview page.'));
// Clear the test-side cache and get the saved field instance.
field_info_cache_clear();
$instance = field_info_instance('node', 'field_test', $this->type);
$format = $instance['display']['default']['type'];
$default_settings = field_info_formatter_settings($format);
$setting_name = key($default_settings);
$setting_value = $instance['display']['default']['settings'][$setting_name];
// Display the "Manage display" screen and check that the expected formatter is
// selected.
$this->drupalGet($manage_display);
$this->assertFieldByName('fields[field_test][type]', $format, t('The expected formatter is selected.'));
$this->assertText("$setting_name: $setting_value", t('The expected summary is displayed.'));
// Change the formatter and check that the summary is updated.
$edit = array('fields[field_test][type]' => 'field_test_multiple', 'refresh_rows' => 'field_test');
$this->drupalPostAJAX(NULL, $edit, array('op' => t('Refresh')));
$format = 'field_test_multiple';
$default_settings = field_info_formatter_settings($format);
$setting_name = key($default_settings);
$setting_value = $default_settings[$setting_name];
$this->assertFieldByName('fields[field_test][type]', $format, t('The expected formatter is selected.'));
$this->assertText("$setting_name: $setting_value", t('The expected summary is displayed.'));
// Submit the form and check that the instance is updated.
$this->drupalPost(NULL, array(), t('Save'));
field_info_cache_clear();
$instance = field_info_instance('node', 'field_test', $this->type);
$current_format = $instance['display']['default']['type'];
$current_setting_value = $instance['display']['default']['settings'][$setting_name];
$this->assertEqual($current_format, $format, t('The formatter was updated.'));
$this->assertEqual($current_setting_value, $setting_value, t('The setting was updated.'));
}
}
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