Problem/Motivation

webform_node_view() permits the 'form' view mode to force display:
// View mode of 'form' is exempted to allow blocks and views to force display.

However, if the 'form' view mode is passed to webform_node_view(), it may result in an undefined index error. $node->content['webform']['visible'] assumes $extra_fields['webform']['visible'] is set, which isn't necessarily true if the 'form' view mode is used.

  // Add the output to the node.
  $node->content['webform'] = array(
    '#theme' => 'webform_view',
    '#node' => $node,
    '#page' => $page,
    '#form' => $form,
    '#enabled' => $enabled,
    '#visible' => $extra_fields['webform']['visible'], // When 'form' view mode is used, $extra_fields['webform']['visible'] isn't set.
    '#weight' => 10,
  );

Proposed resolution

The proposed solution is to set $extra_fields['webform']['visible'] to TRUE if the 'form' view mode is being used:

  // If the webform is not set to display in this view mode, return early.
  // View mode of 'form' is exempted to allow blocks and views to force display.
  $extra_fields = field_extra_fields_get_display('node', $node->type, $view_mode);
  if ($view_mode != 'form' && empty($extra_fields['webform']['visible'])) {
    return;
  }
+  elseif ($view_mode == 'form') {
+   $extra_fields['webform']['visible'] = TRUE;
+  }

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Chris Burge created an issue. See original summary.

Chris Burge’s picture

Liam Morland’s picture

Liam Morland’s picture

Status: Needs review » Postponed (maintainer needs more info)

Under what conditions does the undefined index error appear? At the moment, when such an error happens, #visible will be set to NULL. Setting $extra_fields['webform']['visible'] to TRUE will change this. What is the impact of that change? What if we set $extra_fields['webform']['visible'] to NULL?

Liam Morland’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Please provide steps to reproduce the problem and indicate the expected behavior and the actual behavior.

Chris Burge’s picture

@Liam Morland - Thanks for looking into this issue. I believe I was programmatically rendering a webform inside a custom CTools content type. That said, I no longer have an association with the project for which this patch was developed.