You are here

function disable_breadcrumbs_operations in Disable breadcrumbs 7

Same name and namespace in other branches
  1. 6 disable_breadcrumbs.module \disable_breadcrumbs_operations()

Node operations callback. Called by hook_node_operations.

1 string reference to 'disable_breadcrumbs_operations'
disable_breadcrumbs_node_operations in ./disable_breadcrumbs.module
Implements hook_node_operations().

File

./disable_breadcrumbs.module, line 275
Disable breadcrumbs

Code

function disable_breadcrumbs_operations($nodes, $action) {
  switch ($action) {
    case 'disable_breadcrumbs':
      $enabled_content_types = variable_get('disable_breadcrumbs_node_types', array());
      $all_breadcrumbs_disabled_content_types = variable_get('disable_breadcrumbs_node_types_all', array());
      $message_show = FALSE;
      $not_enabled_content_types = array();
      $disabled_nodes = array();
      foreach ($nodes as $node) {
        $node = node_load($node);
        if (!in_array($node->type, $all_breadcrumbs_disabled_content_types, TRUE) && in_array($node->type, $enabled_content_types, TRUE)) {

          //Use db_merge so we don't get duplicates.
          db_merge('disable_breadcrumbs')
            ->key(array(
            'nid' => $node->nid,
          ))
            ->fields(array(
            'nid' => $node->nid,
            'disable_breadcrumb' => 1,
          ))
            ->execute();
          $message_show = TRUE;
          $disabled_nodes[] = $node->nid;
        }
        elseif (!in_array($node->type, $enabled_content_types, TRUE)) {
          $not_enabled_content_types[] = $node->type;
        }
      }
      if ($message_show) {
        drupal_set_message(t("Breadcrumbs have been disabled for nodes: %nodes", array(
          '%nodes' => implode(", ", $disabled_nodes),
        )));
      }
      if ($not_enabled_content_types) {
        $not_enabled_content_types = array_unique($not_enabled_content_types);
        drupal_set_message(t("Breadcrumbs cannot be disabled for node type(s): %types", array(
          '%types' => implode(", ", $not_enabled_content_types),
        )), 'warning');
      }
      break;
    case 'enable_breadcrumbs':
      disable_breadcrumbs_delete($nodes);
      drupal_set_message(t("Disable breadcrumb status has been unchecked for nodes: %nodes", array(
        '%nodes' => implode(", ", $nodes),
      )));
      break;
  }
}