You are here

function linkit_autocomplete_absolute_url in Linkit 7.3

Retrieve the result object from an absolute URL. Both internal and external paths work.

Parameters

$url: The search string which seems to be an URL.

$parts: An array of URL parts from parse_url().

Return value

A result object. This is an associative array which consists of:

  • title: The title of the result.
  • description: The description of the result (may contain HTML).
  • path: The target path which will be inserted as the href in the link.
  • addClass: A CSS class that will be added to the DOM result item.
1 call to linkit_autocomplete_absolute_url()
linkit_autocomplete in ./linkit.module
Autocomplete callback function.

File

./linkit.module, line 942
Main file for Linkit module.

Code

function linkit_autocomplete_absolute_url($url, $parts) {
  $result = array();

  // Retrieve relevant information about the search string and if its a URL.
  $path_info = linkit_parse_url($url, $parts);

  // Set default options to pass with the url() function if the URL is internal.
  $url_options = array();

  // Add the URL frament.
  $url_options['fragment'] = isset($path_info['fragment']) ? $path_info['fragment'] : '';

  // Add the URL query.
  $url_options['query'] = isset($path_info['query']) ? $path_info['query'] : '';

  // The URL is registerd by Drupal (Internal).
  if (isset($path_info['menu']) && $path_info['system_path'] !== FALSE) {
    $result = array(
      'path' => linkit_get_insert_plugin_processed_path(linkit_get_active_profile(), $path_info['menu']['path'], $url_options),
      'title' => $path_info['menu']['title'] ? check_plain($path_info['menu']['title']) : check_plain($path_info['menu']['path']),
      'description' => check_plain($path_info['menu']['description']) . ' ' . t('This is an internal path.'),
      'addClass' => 'status-ok',
    );
  }
  elseif ($path_info['target'] == 'internal') {
    $result = array(
      'path' => linkit_get_insert_plugin_processed_path(linkit_get_active_profile(), $path_info['path'], $url_options),
      'title' => t('Page not found'),
      'description' => t('This page does not exist or you do not have access to it.'),
      'addClass' => 'status-warning',
    );
  }
  elseif ($path_info['target'] == 'external') {
    $result = array(
      'title' => t('No information available'),
      'description' => t('This is an external URL, but we don\'t know where it leads.'),
      'path' => $path_info['url'],
      'addClass' => 'status-notice',
    );
  }

  // Return the results in an array as BAC will need to have it that way.
  return array(
    $result,
  );
}