Frontend\Core\Engine\Navigation::getURLForExtraId PHP Метод

getURLForExtraId() публичный статический Метод

Fetch the first direct link to an extra id
public static getURLForExtraId ( integer $id, string $language = null ) : string
$id integer The id of the extra.
$language string The language wherein the URL should be retrieved, if not provided we will load the language that was provided in the URL.
Результат string
    public static function getURLForExtraId($id, $language = null)
    {
        $id = (int) $id;
        $language = $language !== null ? (string) $language : LANGUAGE;
        // get the menuItems
        $navigation = self::getNavigation($language);
        // loop types
        foreach ($navigation as $level) {
            // loop level
            foreach ($level as $pages) {
                // loop pages
                foreach ($pages as $properties) {
                    // no extra_blocks available, so skip this item
                    if (!isset($properties['extra_blocks'])) {
                        continue;
                    }
                    // loop extras
                    foreach ($properties['extra_blocks'] as $extra) {
                        // direct link?
                        if ($extra['id'] == $id) {
                            // exact page was found, so return
                            return self::getURL($properties['page_id'], $language);
                        }
                    }
                }
            }
        }
        // fallback
        return self::getURL(404, $language);
    }

Usage Example

Пример #1
0
 /**
  * Fetch an URL based on an extraId
  *    syntax: {{ geturlforextraid($extraId, $language) }}
  *
  * @param int    $extraId  The id of the extra.
  * @param string $language The language to use, if not provided we will use the loaded language.
  *
  * @return string
  */
 public static function getURLForExtraId($extraId, $language = null)
 {
     $language = $language !== null ? (string) $language : null;
     return Navigation::getURLForExtraId((int) $extraId, $language);
 }