This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

deroccha
deroccha

So I try to modify one the Plugin (Menu Manager) to show/hide Menu Items if rainlab.Users session component is added to a page or not. When a new Menu Item is created on Save I want to save the restriction status as boolean. The Plugins has a "File to link To" dropdown where I can select the Target page where to Link my Menu Item on save. I want to check if session component is present or not and return a boolean value. The way as I'm doing is not handy because I loop through of existing pages and I try to catch the matcing one and on the other side if the component is getting removed my Menu Plugin won't know about.

`use Cms\Classes\Page; use Cms\Classes\Theme;

/**
 * Check if page has visbilty restrictions
 * @return boolean
 */

public function getUsersOptions($page){
    $theme = Theme::getEditTheme();
    $pgs = Page::listInTheme($theme, true);

    foreach($pgs as $pg){
        if(array_key_exists('url', $pg->settings)){
            if( !empty($page)){
               if( strpos($pg->settings['url'], $page) && !empty($pg->settings['components']['session'])){
                    $restriction= true;
               } else{
                   $restriction= false;
               }

            } else{
                   $restriction= false;
            }
        }
    }

    return $restriction;
}`

This one is really ugly. Would be good handy a function which would identify the page by it's url and let it like that to parse the desired arguments. Is there a better solution?

Last updated

1-1 of 1

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.