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
- Install the latest version of Panopoly with demo content.
- Log in as an administrator.
- In the Panopoly Magic settings, set the Live Preview to Manual mode.
- Customize one of the starter pages.
- Add a text widget and fill in the fields.
- Activate the Update Preview button.
- Save the widget and the page.
- Visit the dblog.
- 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.