You are here

function draggableviews_contextual_links_view_alter in DraggableViews 7.2

Implements hook_contextual_links_view_alter().

Adds "Order view" contextual link.

File

./draggableviews.module, line 273

Code

function draggableviews_contextual_links_view_alter(&$element, $items) {

  // Check permission to use draggable.
  if (!user_access('access draggableviews')) {
    return;
  }

  // Add Draggableviews contextual link "Order view".
  $views_ui_element = array();
  if (isset($element['#element']['#views_contextual_links_info']['views_ui'])) {
    $views_ui_element = $element['#element']['#views_contextual_links_info']['views_ui'];
  }

  // In case of block #views_contextual_links_info element is inside of
  // 'content' and not '#element' directly.
  // @see http://drupal.org/node/1413596#comment-5912688
  if (empty($views_ui_element) && isset($element['#element']['content']['#views_contextual_links_info']['views_ui'])) {
    $views_ui_element = $element['#element']['content']['#views_contextual_links_info']['views_ui'];
  }
  if (!empty($views_ui_element['view_display_id']) && isset($views_ui_element['view'])) {
    $display_id = $views_ui_element['view_display_id'];
    $view = $views_ui_element['view'];
    $view
      ->build($display_id);

    // Get the order view's path. Don't include itself.
    if ($path = _draggableviews_get_order_path($view, FALSE)) {

      // Only add if current user has access to the order view.
      if ($router_item = menu_get_item($path)) {
        if ($router_item['access']) {
          $element['#links']['draggableviews-order'] = array(
            'title' => t('Order view'),
            'href' => $path,
            'query' => array(
              'destination' => current_path(),
            ),
          );
        }
      }
    }
  }
}