Frontend\Core\Engine\Navigation::getURLForBlock PHP Method

getURLForBlock() public static method

Get the URL for a give module & action combination
public static getURLForBlock ( string $module, string $action = null, string $language = null, array $data = null ) : string
$module string The module wherefore the URL should be build.
$action string The specific action wherefore the URL should be build.
$language string The language wherein the URL should be retrieved, if not provided we will load the language that was provided in the URL.
$data array An array with keys and values that partially or fully match the data of the block. If it matches multiple versions of that block it will just return the first match.
return string
    public static function getURLForBlock($module, $action = null, $language = null, array $data = null)
    {
        $module = (string) $module;
        $action = $action !== null ? (string) $action : null;
        $language = $language !== null ? (string) $language : LANGUAGE;
        // init var
        $pageIdForURL = null;
        // get the menuItems
        $navigation = self::getNavigation($language);
        $dataMatch = false;
        // loop types
        foreach ($navigation as $level) {
            // loop level
            foreach ($level as $pages) {
                // loop pages
                foreach ($pages as $pageId => $properties) {
                    // only process pages with extra_blocks that are visible
                    if (!isset($properties['extra_blocks']) || $properties['hidden']) {
                        continue;
                    }
                    // loop extras
                    foreach ($properties['extra_blocks'] as $extra) {
                        // direct link?
                        if ($extra['module'] == $module && $extra['action'] == $action && $extra['action'] !== null) {
                            // if there is data check if all the requested data matches the extra data
                            if (isset($extra['data']) && $data !== null && array_intersect_assoc($data, (array) $extra['data']) !== $data) {
                                // It is the correct action but has the wrong data
                                continue;
                            }
                            // exact page was found, so return
                            return self::getURL($properties['page_id'], $language);
                        }
                        if ($extra['module'] == $module && $extra['action'] == null) {
                            // if there is data check if all the requested data matches the extra data
                            if (isset($extra['data']) && $data !== null) {
                                if (array_intersect_assoc($data, (array) $extra['data']) !== $data) {
                                    // It is the correct module but has the wrong data
                                    continue;
                                }
                                $pageIdForURL = (int) $pageId;
                                $dataMatch = true;
                            }
                            if ($extra['data'] === null && $data === null) {
                                $pageIdForURL = (int) $pageId;
                                $dataMatch = true;
                            }
                            if (!$dataMatch) {
                                $pageIdForURL = (int) $pageId;
                            }
                        }
                    }
                }
            }
        }
        // pageId still null?
        if ($pageIdForURL === null) {
            return self::getURL(404, $language);
        }
        // build URL
        $url = self::getURL($pageIdForURL, $language);
        // append action
        if ($action !== null) {
            $url .= '/' . Language::act(\SpoonFilter::toCamelCase($action));
        }
        // return the URL
        return $url;
    }

Usage Example

Beispiel #1
0
    public static function getAlbumsForOverview()
    {
        $return = (array) FrontendModel::getContainer()->get('database')->getRecords('	SELECT i.*, m.url, m.data AS meta_data
		 														FROM gallery_albums AS i
																	INNER JOIN meta AS m ON m.id = i.meta_id
																WHERE i.language = ? AND show_in_overview = ?
																ORDER BY sequence ASC', array(FRONTEND_LANGUAGE, 'Y'));
        if (!empty($return)) {
            //--Get link for the categories
            $albumLink = FrontendNavigation::getURLForBlock('Gallery', 'Detail');
            foreach ($return as &$row) {
                //--Create url
                $row['full_url'] = $albumLink . '/' . $row['url'];
                //-- Unserialize
                if (isset($row['meta_data'])) {
                    $row['meta_data'] = @unserialize($row['meta_data']);
                }
                $image = self::getImagesForAlbum($row['id'], 1);
                if (!empty($image)) {
                    foreach ($image as $rowImage) {
                        $row['image'] = $rowImage;
                    }
                }
            }
        }
        return $return;
    }
All Usage Examples Of Frontend\Core\Engine\Navigation::getURLForBlock