backdrop-contrib / ds

Display Suite gives you full control over the way content is displayed without having to maintain dozens of PHP template files.
GNU General Public License v2.0
0 stars 2 forks source link

Warning: Creating default object from empty value in _ds_field_ui_table_layouts() #3

Closed philsward closed 2 years ago

philsward commented 3 years ago

When Select a layout is set to - None -, the following error appears:

Warning: Creating default object from empty value in _ds_field_ui_table_layouts() (line 1566 of /home/user/public_html/t/sandbox/backdrop1.sandbox/modules/ds/includes/ds.field_ui.inc).

Setting the Select a layout to anything other than - None - and saving the page, will remove the errors.

Installing DS and DS UI, then navigating to any "Manage Display" page and configuring a display will present the error.

PHP 7.4.24

philsward commented 3 years ago

No idea if this is right, but it gets rid of the error. And makes the layout pull through ajax where-as before I had to physically save the page to get the Select a layout to take.

Adding $layout = new StdClass(); to line 1566 of /ds/includes/ds.field_ui.inc seems to make things work.

  // Load the layout preview form
  $layout = new StdClass();
  $layout->layout_options = $layout_options;
  _ds_field_ui_table_layouts_preview($form, $form_state, $ds_layouts, $layout, $entity_type, $bundle, $view_mode);

...
philsward commented 3 years ago

Additional testing appears that the location of $layout = new StdClass (); in line 1566 isn't the right fix. The error is gone, however I couldn't get the layout to save.

Instead, this needs to be added starting at line 1558

    '#weight' => -100,
  );

  $layout = new stdClass();
  $layout = ds_get_layout_settings($entity_type, $bundle, $view_mode);
  if (!empty($layout) && isset($layout->layout) && isset($ds_layouts[$layout->layout]) && empty($layout->disabled)) {
    $layout->settings = $layout->settings;
    $layout->regions = $ds_layouts[$layout->layout]['regions'];
    $form['#ds_layout'] = $layout;
  }

  // Load the layout preview form
  $layout->layout_options = $layout_options;
  _ds_field_ui_table_layouts_preview($form, $form_state, $ds_layouts, $layout, $entity_type, $bundle, $view_mode);

Things appear to be working correctly now from this change.

philsward commented 3 years ago

Testing looks pretty good. I'm having problems getting font_awesome_field to save the formatter and (ds extras) ds template, but I have to wonder if it's related to the font awesome field module...

hosef commented 3 years ago

@philsward I made a commit that I think will fix the issue. Could you try testing to see if it works for you?

philsward commented 3 years ago

@hosef so far, no errors :-)

Looks good to me.