You are here

function rules_link_render_link in Rules Link 7

Same name and namespace in other branches
  1. 7.2 rules_link.module \rules_link_render_link()

Renders a link.

Parameters

$rules_link: The link which should be rendered.

$entity_id: The entity id of entity on which the rule should be triggered.

$destination: The destination to which the Rules Module should redirect the user after triggering the link.

$parameters: Additional parameters for the Rules components of the link.

Return value

A renderable array.

3 calls to rules_link_render_link()
rules_link_entity_view in ./rules_link.module
Implement hook_entity_view().
rules_link_render in ./rules_link.module
Renders a link using the name of the rules_link and the entity id.
views_handler_field_rules_link::render in ./rules_link.views.inc
Render the field.

File

./rules_link.module, line 185
Rules Link - module file.

Code

function rules_link_render_link($rules_link, $entity_id, $destination = NULL, $parameters = array()) {
  if (rules_link_check_visibility($rules_link, array_merge(array(
    $entity_id,
  ), $parameters))) {
    $path = $rules_link->path . '/' . $entity_id;
    if (count($parameters) > 0) {
      $path .= '/' . implode('/', $parameters);
    }
    $path .= $rules_link->settings['link_type'] == 'confirm' ? '' : '/' . rules_link_get_token($entity_id);
    $link = array(
      '#title' => $rules_link
        ->getSettingTranslation('text'),
      '#href' => $path,
      '#attr' => array(
        'class' => array(
          'rules-link',
        ),
        'rel' => 'nofollow',
      ),
      '#rules_link' => $rules_link,
      '#theme' => 'rules_link',
    );
    if ($rules_link->settings['link_type'] == 'javascript') {
      $link['#attr']['class'][] = 'rules-link-js';
      drupal_add_js(drupal_get_path('module', 'rules_link') . '/rules_link.js', 'file');
      drupal_add_css(drupal_get_path('module', 'rules_link') . '/rules_link.css', 'file');
    }
    else {
      $link['#options'] = array(
        'query' => $destination,
      );
    }
    return $link;
  }
  return array();
}