You are here

function _panopoly_widgets_content_item_form_submit in Panopoly Widgets 7

Submission callback for 'Content Item' widget's exposed form.

1 string reference to '_panopoly_widgets_content_item_form_submit'
panopoly_widgets_form_views_content_views_panes_content_type_edit_form_alter in ./panopoly_widgets.module
Implements hook_form_FORM_ID_alter().

File

./panopoly_widgets.module, line 869

Code

function _panopoly_widgets_content_item_form_submit($form, &$form_state) {
  $exposed =& $form_state['values']['exposed'];
  if ($exposed['title'] != $form_state['original_title']) {

    // If the title has changed, we need to load the node with that title, set
    // the NID, and then clear out the title. We use the View itself to query
    // so that the result is consistent with autocomplete.
    $view = views_get_view('panopoly_widgets_general_content');
    $view
      ->set_display('piece_of_content');
    $view
      ->set_exposed_input($exposed);
    $view
      ->pre_execute();
    $view
      ->execute($view->current_display);
    $view
      ->post_execute();
    if (count($view->result) > 0) {
      $exposed['nid'] = $view->result[0]->nid;
      $exposed['title'] = '';
    }
  }
  else {

    // If the title hasn't change, we just revert back to the original NID.
    $exposed['nid'] = $form_state['original_nid'];
    $exposed['title'] = '';
  }
}