function panopoly_widgets_form_views_content_views_panes_content_type_edit_form_alter in Panopoly Widgets 7
Implements hook_form_FORM_ID_alter().
File
- ./
panopoly_widgets.module, line 825
Code
function panopoly_widgets_form_views_content_views_panes_content_type_edit_form_alter(&$form, &$form_state) {
$view = $form_state['view'];
if ($view->name == 'panopoly_widgets_general_content' && $view->current_display == 'piece_of_content') {
$exposed =& $form['exposed'];
// Disable maxlength on autocomplete field because node titles can be long,
// leading to a validation error, preventing the user from referencing them.
// We need to do this here as well as above in the alter hook for
// 'views_exposed_form' because there situations where that doesn't run.
$exposed['filter-title']['title']['#maxlength'] = NULL;
// Set required on the form rather than the View because we need to allow
// either 'title' or 'nid' when actually rendering the View.
$exposed['filter-title']['#required'] = TRUE;
$exposed['filter-title']['title']['#required'] = TRUE;
// If the user updated panopoly_widgets, but hasn't run the update function
// panopoly_wigets_update_7012() yet, then bail out because this code can
// actually break this widget entirely.
if (empty($exposed['filter-nid'])) {
return;
}
// If we have a value for NID, then we use that to set the title and then
// clear out and hide the NID. This allows the user to chose the node using
// the title autocomplete.
if (!empty($exposed['filter-nid']['nid']['#default_value'])) {
if ($node = node_load($exposed['filter-nid']['nid']['#default_value'])) {
$form_state['original_nid'] = $node->nid;
$form_state['original_title'] = $node->title;
$exposed['filter-title']['title']['#default_value'] = $node->title;
}
}
$exposed['filter-nid']['nid']['#default_value'] = '';
$exposed['filter-nid']['#access'] = FALSE;
// Add a submit callback that will convert back from the title to the NID.
array_unshift($form['#submit'], '_panopoly_widgets_content_item_form_submit');
}
}