Problem/Motivation

When previews are set to Manual, updating the preview of a non-FAPE widget causes PHP warnings:
Warning: Undefined array key "plugin" in panopoly_magic_ajax_update_preview() (line 694 of panopoly_magic.module).
Warning: Trying to access array offset on value of type null in panopoly_magic_ajax_update_preview() (line 694 of panopoly_magic.module).

Steps to reproduce

  1. Install the latest version of Panopoly with demo content.
  2. Log in as an administrator.
  3. In the Panopoly Magic settings, set the Live Preview to Manual mode.
  4. Customize one of the starter pages.
  5. Add a text widget and fill in the fields.
  6. Activate the Update Preview button.
  7. Save the widget and the page.
  8. Visit the dblog.
  9. Note the PHP warnings.

Proposed resolution

This code is causing the warnings:

  // If this is a field is being editted via FAPE, then we need to update the
  // entity in context with the temporary value of the field, in order for it
  // to be rendered correctly in the preview.
  if (isset($form_state['values']) && $form_state['plugin']['name'] == 'entity_field' && isset($form_state['subform_id']) && $form_state['subform_id'] == 'fape_field_edit_field_form' && isset($form['#panopoly_magic_preview_info']['context']['panelizer'])) {
    $entity_type = $form['#panopoly_magic_preview_info']['context']['panelizer']->type[2];
    $entity =& $form['#panopoly_magic_preview_info']['context']['panelizer']->data;
    foreach ($form_state['field'] as $field_name => $lang_field) {
      field_attach_form_validate($entity_type, $entity, $form, $form_state, array('field_name' => $field_name));
      field_attach_submit($entity_type, $entity, $form, $form_state, array('field_name' => $field_name));

      // Run the hook_field_load() before rendering. This is necessary for some
      // fields, like file and image fields.
      list ($entity_id,,) = entity_extract_ids($entity_type, $entity);
      $a = FIELD_LOAD_CURRENT;
      $b = NULL;
      _field_invoke_multiple('load', $entity_type, array($entity_id => $entity), $a, $b, array('field_name' => $field_name));
    }
  }

There is no "plugin" array key for text widgets and other non-FAPE widgets. Add a condition that checks for the presence of the array key.

Remaining tasks

Patch and test.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

cboyden created an issue. See original summary.

cboyden’s picture

Assigned: cboyden » Unassigned
Status: Active » Needs review
StatusFileSize
new1.2 KB

See attached patch.

  • dsnopek committed 6fdb7982 on 7.x-1.x authored by cboyden
    Issue #3349211 by cboyden: PHP warnings when updating previews of non-...
dsnopek’s picture

Status: Needs review » Fixed

Merged. Thanks!

Status: Fixed » Closed (fixed)

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