1 path.module path_get_pattern_by_entity_type($entity_type, $bundle = '', $langcode = LANGUAGE_NONE)

Load an URL alias pattern by entity, bundle, and language.

Parameters

string $entity_type: An entity type (e.g. node, taxonomy, user, etc.)

string $bundle: A bundle (e.g. content type, vocabulary ID, etc.)

string $langcode: A language code, defaults to the LANGUAGE_NONE constant.

File

core/modules/path/path.module, line 641
Enables users to customize URLs and provide automatic URL alias patterns.

Code

function path_get_pattern_by_entity_type($entity_type, $bundle = '', $langcode = LANGUAGE_NONE) {
  $config = config('path.settings');
  $patterns = &backdrop_static(__FUNCTION__, array());

  $pattern_id = "$entity_type:$bundle:$langcode";

  if (!isset($patterns[$pattern_id])) {
    $variables = array();
    if ($langcode != LANGUAGE_NONE) {
      $variables[] = "{$entity_type}_{$bundle}_{$langcode}_pattern";
    }
    if ($bundle) {
      $variables[] = "{$entity_type}_{$bundle}_pattern";
    }
    $variables[] = "{$entity_type}_pattern";

    foreach ($variables as $variable) {
      if ($pattern = trim((string) $config->get($variable))) {
        break;
      }
    }

    $patterns[$pattern_id] = $pattern;
  }

  return $patterns[$pattern_id];
}