You are here

function ccl_actions_trigger in Custom Contextual Links 8

Same name and namespace in other branches
  1. 7 ccl_actions/ccl_actions.module \ccl_actions_trigger()

Trigger function to execute actions.

1 string reference to 'ccl_actions_trigger'
ccl_actions_menu in ccl_actions/ccl_actions.module
Implements hook_menu().

File

ccl_actions/ccl_actions.module, line 284
Implementation of core actions for CCL.

Code

function ccl_actions_trigger($node, $action, $state) {
  if (!node_access('update', $node)) {
    drupal_set_message(t('You have no permission to update %node_title.', array(
      '%node_title' => $node->title,
    )), 'error');
    drupal_goto();
  }
  switch ($action) {
    case 'status':
      if ($state) {
        actions_do('node_publish_action', $node);
        $node
          ->save();
        drupal_set_message(t('%node_title has been published.', array(
          '%node_title' => $node->title,
        )));
      }
      else {
        $res = actions_do('node_unpublish_action', $node);
        $node
          ->save();
        drupal_set_message(t('%node_title has been unpublished.', array(
          '%node_title' => $node->title,
        )));
      }
      break;
    case 'sticky':
      if ($state) {
        actions_do('node_make_sticky_action', $node);
        $node
          ->save();
        drupal_set_message(t('%node_title has been made sticky.', array(
          '%node_title' => $node->title,
        )));
      }
      else {
        $res = actions_do('node_make_unsticky_action', $node);
        $node
          ->save();
        drupal_set_message(t('%node_title has been made unsticky.', array(
          '%node_title' => $node->title,
        )));
      }
      break;
    case 'promote':
      if ($state) {
        actions_do('node_promote_action', $node);
        $node
          ->save();
        drupal_set_message(t('%node_title has been promoted to front page.', array(
          '%node_title' => $node->title,
        )));
      }
      else {
        $res = actions_do('node_unpromote_action', $node);
        $node
          ->save();
        drupal_set_message(t('%node_title has been removed from front page.', array(
          '%node_title' => $node->title,
        )));
      }
      break;
  }

  // Return to set destination parameter.
  drupal_goto();
}