protected function setContext(MenuItemInterface $item,
        array $routeParameters = array(),
        array $options = array())
    {
        $display  = true;
        $rootItem = !$item->getName();
        $token    = $this->security->getToken();

        if ($token) {
            if ($options['roles'] && !$this->security->isGranted($options['roles'])) {
                $display = false;
            }


            if ($display) {
                foreach ((array) $item->getExtra('oids') as $oidItem) {
                    if (!$this->security->isGranted($oidItem['permissions'], $oidItem['oid'])) {
                        $display = false;
                        break;
                    }
                }
            }
        }

        if ($options['route'] && !$rootItem) {
            $acceptedRouteParameters = array_intersect_key($routeParameters, $options['routeAcceptedParameters']);

            if ($options['routeRequiredParameters'] === $options['routeAcceptedParameters']) {
                $uri = $this->router->generate(
                    $options['route'],
                    $acceptedRouteParameters,
                    $options['routeAbsolute']
                );
                $item->setUri($uri);
            } else {
                $display = false;
            }
        }

        if (!$display) {
            if ($options['showNonAuthorized'] && !$token) {
                $display = true;
            }
            if ($options['showAsText']) {
                $display = true;
                $item->setUri(null);
            }
        }

        if (!$display) {
            $item->setDisplay(false);
        }

        return $this;
    }