You are here

function crumbs_build_method_suffix in Crumbs, the Breadcrumbs suite 6.2

Same name and namespace in other branches
  1. 7 crumbs.module \crumbs_build_method_suffix()

This function has exactly one possible input value for each possible return value, except the return value FALSE.

Parameters

$router_path :string: The router path can contain any character, but will typically have a format like "node/%/edit".

Return value

:string or FALSE A string that can be used as a method suffix, or FALSE, where that is not possible. The route "node/%/edit" will resolve as "node_x_edit".

1 call to crumbs_build_method_suffix()
crumbs_InvokeAction_findForPath::__construct in ./crumbs.plugin_engine.inc

File

./crumbs.module, line 158

Code

function crumbs_build_method_suffix($router_path) {
  $method_suffix = strtolower($router_path);
  $method_suffix = preg_replace('#[^a-z0-9\\%]#', '_', $method_suffix);
  $method_suffix = strtr($method_suffix, array(
    '%' => 'x',
  ));
  $reverse = strtr($method_suffix, array(
    '_' => '/',
  ));
  $reverse = preg_replace(array(
    '#/x/#',
    '#/x$#',
  ), array(
    '/%/',
    '/%',
  ), $reverse);

  // we need to do this two time to catch things like "/x/x/x/x".
  $reverse = strtr($reverse, array(
    '/x/' => '/%/',
  ));
  if ($reverse === $router_path) {
    return $method_suffix;
  }
  return FALSE;
}