You are here

function rules_link_entity_view in Rules Link 7

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

Implement hook_entity_view().

File

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

Code

function rules_link_entity_view($entity, $type, $view_mode, $langcode) {
  $links = array();
  $rules_links = rules_link_get_links();
  foreach ($rules_links as $name => $rules_link) {
    if ($rules_link->entity_type == $type && $rules_link->settings['entity_link']) {
      list($id, $rev, $bundle) = entity_extract_ids($type, $entity);

      // If the link is restricted to some bundles, verify the bundle.
      // If it should be only shown on certain view modes, check the view modes.
      if ($id && (empty($rules_link->settings['bundles']) || in_array($bundle, $rules_link->settings['bundles'])) && (empty($rules_link->settings['view_mode']) || in_array($view_mode, $rules_link->settings['view_mode']))) {
        $rendered_link = rules_link_render_link($rules_link, $id, drupal_get_destination());
        if (!empty($rendered_link)) {
          $links[$name] = drupal_render($rendered_link);
        }
      }
    }
  }
  foreach ($links as $name => $link) {
    $entity->content['rules_links_' . $name] = array(
      '#markup' => $link,
    );
  }
}