Problem/Motivation

If a field formatter has cascaded settings e.g. $settings['markup'] = array('wrapper' => 'div', 'classes' => 'i-m-a-class') it's not possible to set the settings in panels / panelizer.
As far as I see this is because ctools_fields_get_field_formatter_settings_form() doesn't set the #tree property to the field formatter settings form.
But field_ui.admin.inc (line 912) does this:

  $table = array(
    '#type' => 'field_ui_table',
    '#tree' => TRUE,

...

      if ($settings_form) {
        $table[$name]['format']['#cell_attributes'] = array('colspan' => 3);
        $table[$name]['format']['settings_edit_form']

This means the settings form is also affected by the #tree property.
Debugging further shows that without the #tree property the function ctools_entity_field_content_type_formatter_styles_submit() can't find the cascaded field formatter settings in the form values and thus those settings are ignored.

Proposed resolution

Set the #tree property in ctools_fields_get_field_formatter_settings_form().

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

The structure of the form values changes.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

das-peter’s picture

Title: ctools_fields_get_field_formatter_settings_form() not fully compatibly to field_ui » ctools_fields_get_field_formatter_settings_form() not fully compatible to field_ui
das-peter’s picture

Status: Active » Needs review
kristiaanvandeneynde’s picture

Status: Needs review » Reviewed & tested by the community

Tested to work, thanks for the patch!

Anybody’s picture

Thanks a lot. It would be great to have this in the next .dev release. Is that possible?

Anybody’s picture

Priority: Normal » Major

Who will have a look at this and take this into dev? :)
This is really problematic for some modules. I hope it is okay though to set the priority up.

ItangSanjana’s picture

FYI, issue on https://www.drupal.org/node/1876522 is fixed by applying the patch above. Thanks.

TanvirAhmad’s picture

Patch worked for me as well. Thanks.

mdeltito’s picture

+1 for this patch, this resolves issues with the settings for bg_image_formatter

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Looks good, Committed.

kristiaanvandeneynde’s picture

Ugh, just noticed something after this got committed:

+++ b/includes/fields.inc
@@ -78,6 +78,7 @@ function ctools_fields_get_field_formatter_settings_form($field, $formatter_type
     $settings_form = $function($field, $instance, $view_mode, $form, $form_state);
+    $settings_form['#tree'] = TRUE;
     if ($settings_form) {

Should be:

+++ b/includes/fields.inc
@@ -78,6 +78,7 @@ function ctools_fields_get_field_formatter_settings_form($field, $formatter_type
     $settings_form = $function($field, $instance, $view_mode, $form, $form_state);
     if ($settings_form) {
+      $settings_form['#tree'] = TRUE;

Otherwise the if-statement is always TRUE.

maximpodorov’s picture

I created the new issue and attached the patch (using the change kristiaanvandeneynde proposed) here: #2397709: Set #tree property in the proper place

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.