You are here

function _views_navigation_replace_href_in_html in Views navigation 7

Helper function to replace the links in HTML.

Parameters

string $html: The HTML to replace links in.

object $entity: The entity to render.

object $view: The views object.

3 calls to _views_navigation_replace_href_in_html()
views_navigation_handler_entity_field_entity::render in views/views_navigation_handler_entity_field_entity.inc
Render callback.
views_navigation_plugin_ds_entity_view::render in views/views_navigation_plugin_ds_entity_view.inc
Render callback.
views_navigation_plugin_entity_row_entity_view::render in views/views_navigation_plugin_entity_row_entity_view.inc
Render callback.

File

./views_navigation.inc, line 506
Views navigation main include file.

Code

function _views_navigation_replace_href_in_html(&$html, $entity, $view) {
  $entity_type = _views_navigation_get_entity_type($view->query);
  $uri = entity_uri($entity_type, $entity);
  $alias = base_path() . drupal_get_path_alias($uri['path']);
  $path = url($uri['path'], array(
    'absolute' => TRUE,
  ));
  $pattern = '@href="(' . $path . '|' . $alias . ')"@';
  if (preg_match($pattern, $html)) {
    $id_key = _views_navigation_get_id_key($entity_type);
    $url = _views_navigation_build_url($entity->{$id_key}, $view, [
      'absolute' => FALSE,
    ]);
    $html = preg_replace($pattern, 'href="' . $url . '"', $html);
  }
}