You are here

function _access_unpublished_show_hashed_link in Access unpublished 7

Display the hashed link to the end user.

Parameters

string: The original URL

$node: The node being displayed, passed by reference

1 call to _access_unpublished_show_hashed_link()
_access_unpublished_check_hashed_link in ./access_unpublished.module
Helper function to determine whether to display a hashed link and if so, determine its format.

File

./access_unpublished.module, line 246
Drupal module: Access unpublished.

Code

function _access_unpublished_show_hashed_link($url, &$node) {

  // Add css for access_unpublished.
  $module_path = drupal_get_path('module', 'access_unpublished');
  drupal_add_css($module_path . '/css/access_unpublished.css');

  // Construct URL link.
  $au_url_key = variable_get('access_unpublished_url_key', 'hash');
  $au_link = l(t("hashed link"), $url, array(
    'query' => array(
      $au_url_key => _access_unpublished_get_hash_from_nodeid($node->nid),
    ),
    'attributes' => array(
      'class' => array(
        'access_unpublished_link',
      ),
    ),
  ));
  $au_link_text = t("You can use !link to view this unpublished content.", array(
    '!link' => $au_link,
  ));
  if (variable_get('access_unpublished_display_link_in_drupal_message', 1)) {

    // Show link in Drupal message. Avoid duplicates produced by an active
    // class that might be set on an existing message which are not caught
    // by drupal_set_message(). This edge case can be triggered if e.g.
    // the main site theme does not display drupal messages but the admin
    // theme does and the site is configured to show hash links on the node
    // edit page; in this case, viewing the node and then editing its draft
    // will produce duplicate messages on the node edit form.
    $messages = drupal_get_messages('status');
    if (!empty($messages['status'])) {
      foreach ($messages['status'] as $message) {
        if (strpos($message, 'access_unpublished_link') === FALSE) {

          // drupal_get_messages() above clears all status messages by default,
          // including any possible duplicates. Add back any status messages
          // from other modules we'd like to keep here.
          drupal_set_message($message, 'status', FALSE);
        }
      }
    }
    drupal_set_message($au_link_text, 'status', FALSE);
  }
  if (variable_get('access_unpublished_display_link_in_node_content', 1)) {

    // Show link in extra renderable entry in node contents.
    $node->content['access_unpublished_link'] = array(
      '#access_unpublished_link' => $au_link_text,
      '#weight' => 100,
      '#theme' => 'access_unpublished_link',
    );
  }
}