You are here

function _ccl_actions_prepare_link in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl_actions/ccl_actions.module \_ccl_actions_prepare_link()

Helper function to create the action link.

This fuunctions also checks if the current user has edit rights for this node.

1 call to _ccl_actions_prepare_link()
ccl_actions_ccl_add_link in ccl_actions/ccl_actions.module
Hook function to process the contextual links element.

File

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

Code

function _ccl_actions_prepare_link($actions, $node, &$element, $dest) {
  if (!node_access('update', $node)) {
    return FALSE;
  }
  foreach ($actions as $action) {
    switch ($action) {
      case 'publish':
        if ($node->status) {
          $link = array(
            'href' => 'admin/config/user-interface/ccl/action-trigger/' . $node->nid . '/status/0',
            'title' => t('Unpublish content'),
            'query' => array(
              $dest,
            ),
          );
        }
        else {
          $link = array(
            'href' => 'admin/config/user-interface/ccl/action-trigger/' . $node->nid . '/status/1',
            'title' => t('Publish content'),
            'query' => array(
              $dest,
            ),
          );
        }
        $element['#links']['ccl-action-status-' . $node->nid] = $link;
        break;
      case 'sticky':
        if ($node->sticky) {
          $link = array(
            'href' => 'admin/config/user-interface/ccl/action-trigger/' . $node->nid . '/sticky/0',
            'title' => t('Make content unsticky'),
            'query' => array(
              $dest,
            ),
          );
        }
        else {
          $link = array(
            'href' => 'admin/config/user-interface/ccl/action-trigger/' . $node->nid . '/sticky/1',
            'title' => t('Make content sticky'),
            'query' => array(
              $dest,
            ),
          );
        }
        $element['#links']['ccl-action-sticky-' . $node->nid] = $link;
        break;
      case 'promote':
        if ($node->promote) {
          $link = array(
            'href' => 'admin/config/user-interface/ccl/action-trigger/' . $node->nid . '/promote/0',
            'title' => t('Remove content from front page'),
            'query' => array(
              $dest,
            ),
          );
        }
        else {
          $link = array(
            'href' => 'admin/config/user-interface/ccl/action-trigger/' . $node->nid . '/promote/1',
            'title' => t('Promote content to front page'),
            'query' => array(
              $dest,
            ),
          );
        }
        $element['#links']['ccl-action-promote-' . $node->nid] = $link;
        break;
    }
  }
}