public function isActive(EntityInterface $item)
    {
        if ($item->has('activation') && is_callable($item->get('activation'))) {
            $callable = $item->get('activation');

            return $callable($this->_View->request, $item);
        }

        $itemUrl = $this->sanitize($item->get('url'));
        if (!str_starts_with($itemUrl, '/')) {
            return false;
        }

        switch ($item->get('activation')) {
            case 'any':
                return $this->_requestMatches($item->get('active'));
            case 'none':
                return !$this->_requestMatches($item->get('active'));
            case 'php':
                return php_eval($item->get('active'), [
                    'view', &$this->_View,
                    'item', &$item,
                ]) === true;
            case 'auto':
            default:
                static $requestUri = null;
                static $requestUrl = null;

                if ($requestUri === null) {
                    $requestUri = urldecode(env('REQUEST_URI'));
                    $requestUrl = str_replace('//', '/', '/' . urldecode($this->_View->request->url) . '/');
                }

                $isInternal =
                    $itemUrl !== '/' &&
                    str_ends_with($itemUrl, str_replace_once($this->baseUrl(), '', $requestUri));
                $isIndex =
                    $itemUrl === '/' &&
                    $this->_View->request->isHome();
                $isExact =
                    str_replace('//', '/', "{$itemUrl}/") === $requestUrl ||
                    $itemUrl == $requestUri;

                if ($this->config('breadcrumbGuessing')) {
                    return ($isInternal || $isIndex || $isExact || in_array($itemUrl, $this->_crumbs()));
                }

                return ($isInternal || $isIndex || $isExact);
        }
    }
public function isActive(EntityInterface $item)
    {
        if ($item->has('activation') && is_callable($item->get('activation'))) {
            $callable = $item->get('activation');

            return $callable($this->_View->request, $item);
        }

        $itemUrl = $this->sanitize($item->get('url'));
        if (!str_starts_with($itemUrl, '/')) {
            return false;
        }

        switch ($item->get('activation')) {
            case 'any':
                return $this->_requestMatches($item->get('active'));
            case 'none':
                return !$this->_requestMatches($item->get('active'));
            case 'php':
                return php_eval($item->get('active'), [
                    'view', &$this->_View,
                    'item', &$item,
                ]) === true;
            case 'auto':
            default:
                static $requestUri = null;
                static $requestUrl = null;

                if ($requestUri === null) {
                    $requestUri = urldecode(env('REQUEST_URI'));
                    $requestUrl = str_replace('//', '/', '/' . urldecode($this->_View->request->url) . '/');
                }

                $isInternal =
                    $itemUrl !== '/' &&
                    str_ends_with($itemUrl, str_replace_once($this->baseUrl(), '', $requestUri));
                $isIndex =
                    $itemUrl === '/' &&
                    $this->_View->request->isHome();
                $isExact =
                    str_replace('//', '/', "{$itemUrl}/") === $requestUrl ||
                    $itemUrl == $requestUri;

                if ($this->config('breadcrumbGuessing')) {
                    return ($isInternal || $isIndex || $isExact || in_array($itemUrl, $this->_crumbs()));
                }

                return ($isInternal || $isIndex || $isExact);
        }
    }
public function isActive ( EntityInterface $ item ) { if ( $ item -> has ( 'activation' ) && is_callable ( $ item -> get ( 'activation' ) ) ) { $ callable = $ item -> get ( 'activation' ) ; return $ callable ( $ this -> _View -> request , $ item ) ; } $ itemUrl = $ this -> sanitize ( $ item -> get ( 'url' ) ) ; if ( ! str_starts_with ( $ itemUrl , '/' ) ) { return false ; } switch ( $ item -> get ( 'activation' ) ) { case 'any' : return $ this -> _requestMatches ( $ item -> get ( 'active' ) ) ; case 'none' : return ! $ this -> _requestMatches ( $ item -> get ( 'active' ) ) ; case 'php' : return php_eval ( $ item -> get ( 'active' ) , [ 'view' , & $ this -> _View , 'item' , & $ item , ] ) === true ; case 'auto' : default : static $ requestUri = null ; static $ requestUrl = null ; if ( $ requestUri === null ) { $ requestUri = urldecode ( env ( 'REQUEST_URI' ) ) ; $ requestUrl = str_replace ( '//' , '/' , '/' . urldecode ( $ this -> _View -> request -> url ) . '/' ) ; } $ isInternal = $ itemUrl !== '/' && str_ends_with ( $ itemUrl , str_replace_once ( $ this -> baseUrl ( ) , '' , $ requestUri ) ) ; $ isIndex = $ itemUrl === '/' && $ this -> _View -> request -> isHome ( ) ; $ isExact = str_replace ( '//' , '/' , "{$itemUrl}/" ) === $ requestUrl || $ itemUrl == $ requestUri ; if ( $ this -> config ( 'breadcrumbGuessing' ) ) { return ( $ isInternal || $ isIndex || $ isExact || in_array ( $ itemUrl , $ this -> _crumbs ( ) ) ) ; } return ( $ isInternal || $ isIndex || $ isExact ) ; } }
Checks if the given menu link should be marked as active.

If `$item->activation` is a callable function it will be used to determinate
if the link should be active or not, returning true from callable indicates
link should be active, false indicates it should not be marked as active.
Callable receives current request object as first argument and $item as second.

`$item->url` property MUST exists if "activation" is not a callable, and can
be either:

- A string representing an external or internal URL (all internal links must
starts with "/"). e.g. `/user/login`

- An array compatible with \Cake\Routing\Router::url(). e.g. `['controller'
=> 'users', 'action' => 'login']`

Both examples are equivalent.

@param \Cake\Datasource\EntityInterface $item A menu's item
@return bool
Checks if the given menu link should be marked as active .