RainLab\Blog\Models\Category::getMenuTypeInfo PHP Method

getMenuTypeInfo() public static method

Returns a menu item type information. The type information is returned as array with the following elements: - references - a list of the item type reference options. The options are returned in the ["key"] => "title" format for options that don't have sub-options, and in the format ["key"] => ["title"=>"Option title", "items"=>[...]] for options that have sub-options. Optional, required only if the menu item type requires references. - nesting - Boolean value indicating whether the item type supports nested items. Optional, false if omitted. - dynamicItems - Boolean value indicating whether the item type could generate new menu items. Optional, false if omitted. - cmsPages - a list of CMS pages (objects of the Cms\Classes\Page class), if the item type requires a CMS page reference to resolve the item URL.
public static getMenuTypeInfo ( string $type ) : array
$type string Specifies the menu item type
return array Returns an array
    public static function getMenuTypeInfo($type)
    {
        $result = [];
        if ($type == 'blog-category') {
            $result = ['references' => self::listSubCategoryOptions(), 'nesting' => true, 'dynamicItems' => true];
        }
        if ($type == 'all-blog-categories') {
            $result = ['dynamicItems' => true];
        }
        if ($result) {
            $theme = Theme::getActiveTheme();
            $pages = CmsPage::listInTheme($theme, true);
            $cmsPages = [];
            foreach ($pages as $page) {
                if (!$page->hasComponent('blogPosts')) {
                    continue;
                }
                /*
                 * Component must use a category filter with a routing parameter
                 * eg: categoryFilter = "{{ :somevalue }}"
                 */
                $properties = $page->getComponentProperties('blogPosts');
                if (!isset($properties['categoryFilter']) || !preg_match('/{{\\s*:/', $properties['categoryFilter'])) {
                    continue;
                }
                $cmsPages[] = $page;
            }
            $result['cmsPages'] = $cmsPages;
        }
        return $result;
    }

Usage Example

Example #1
0
 public function boot()
 {
     Event::listen('pages.menuitem.listTypes', function () {
         return ['blog-category' => 'Blog category', 'all-blog-categories' => 'All blog categories'];
     });
     Event::listen('pages.menuitem.getTypeInfo', function ($type) {
         if ($type == 'blog-category' || $type == 'all-blog-categories') {
             return Category::getMenuTypeInfo($type);
         }
     });
     Event::listen('pages.menuitem.resolveItem', function ($type, $item, $url, $theme) {
         if ($type == 'blog-category' || $type == 'all-blog-categories') {
             return Category::resolveMenuItem($item, $url, $theme);
         }
     });
 }
All Usage Examples Of RainLab\Blog\Models\Category::getMenuTypeInfo