You are here

function search_api_exclude_form_node_type_form_submit in Search API exclude 7

Custom additional submit handler for node_type_form().

1 string reference to 'search_api_exclude_form_node_type_form_submit'
search_api_exclude_form_node_type_form_alter in ./search_api_exclude.module
Implements hook_form_FORM_ID_alter() for node_type_form().

File

./search_api_exclude.module, line 140
Allows users to exclude specific nodes from indexing by Search API.

Code

function search_api_exclude_form_node_type_form_submit(array $form, array &$form_state) {
  if (isset($form_state['values']['search_api_exclude_setting']) && !empty($form['#node_type']->type)) {
    $type = $form['#node_type']->type;
    $types = variable_get('search_api_exclude_types', array());
    if (!empty($types[$type]) != (bool) $form_state['values']['search_api_exclude_setting']) {
      if ($form_state['values']['search_api_exclude_setting']) {
        $types[$type] = TRUE;
      }
      else {
        unset($types[$type]);

        // Remove all the nodes of this type from our "Exclude" list and mark
        // them as changed for the Search API.
        $select = db_select('search_api_exclude', 'e')
          ->fields('e', array(
          'nid',
        ));
        $select
          ->join('node', 'n', 'n.nid = e.nid');
        $nids = $select
          ->condition('n.type', $type)
          ->execute()
          ->fetchCol();
        if (isset($nids) && !empty($nids)) {
          db_delete('search_api_exclude')
            ->condition('nid', $nids)
            ->execute();
          foreach (node_load_multiple($nids) as $node) {
            search_api_entity_update($node, 'node');
          }
        }
      }
      variable_set('search_api_exclude_types', $types);
    }
  }
}