You are here

function shurly_path_available in ShURLy 8

Same name and namespace in other branches
  1. 6 shurly.module \shurly_path_available()
  2. 7 shurly.module \shurly_path_available()

Checks to see if there's a menu handler, path alias, or language prefix for a given path

Return value

TRUE if there are no conflicts

4 calls to shurly_path_available()
ShurlyCreateForm::validateForm in src/Form/ShurlyCreateForm.php
Form validation handler.
shurly_generate_random in ./shurly.module
Generate a random short URL Pretty much unused at this point this method could take a LOOOONG time on a site with lots of URLs
shurly_next_url in ./shurly.module
Return next available short URL.
shurly_shorten in ./shurly.module
API function to shorten a URL.

File

./shurly.module, line 544
Description http://www.youtube.com/watch?v=Qo7qoonzTCE.

Code

function shurly_path_available($path) {

  // Check to see if path represents an enabled language.
  $languages = \Drupal::LanguageManager()
    ->getLanguages();
  if (array_key_exists($path, $languages)) {
    return FALSE;
  }
  $return = TRUE;

  // See if $path is an alias.
  $source = \Drupal::service('path_alias.manager')
    ->getAliasByPath('/' . $path);
  if ($source != $path) {

    // If so, set alias source to $path.
    $path = $source;
  }
  $url_object = \Drupal::service('path.validator')
    ->getUrlIfValid($path);
  if ($url_object) {
    $return = FALSE;
  }
  return $return;
}