public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
    {
        // Direct access to Tag
        if ($name instanceof Tag) {
            return $this->generator->generate($name, $parameters, $referenceType);
        }

        // Normal route name
        if ($name === self::TAG_URL_ROUTE_NAME) {
            if (isset($parameters['tag']) || isset($parameters['tagId'])) {
                // Check if tag is a valid Tag object
                if (isset($parameters['tag']) && !$parameters['tag'] instanceof Tag) {
                    throw new LogicException(
                        "When generating a Tag route, 'tag' parameter must be a valid Netgen\\TagsBundle\\API\\Repository\\Values\\Tags\\Tag."
                    );
                }

                $tag = isset($parameters['tag']) ? $parameters['tag'] : $this->tagsService->loadTag($parameters['tagId']);
                unset($parameters['tag'], $parameters['tagId'], $parameters['viewType'], $parameters['layout']);

                return $this->generator->generate($tag, $parameters, $referenceType);
            }

            throw new InvalidArgumentException(
                "When generating a Tag route, either 'tag' or 'tagId' must be provided."
            );
        }

        throw new RouteNotFoundException('Could not match route');
    }
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
    {
        // Direct access to Tag
        if ($name instanceof Tag) {
            return $this->generator->generate($name, $parameters, $referenceType);
        }

        // Normal route name
        if ($name === self::TAG_URL_ROUTE_NAME) {
            if (isset($parameters['tag']) || isset($parameters['tagId'])) {
                // Check if tag is a valid Tag object
                if (isset($parameters['tag']) && !$parameters['tag'] instanceof Tag) {
                    throw new LogicException(
                        "When generating a Tag route, 'tag' parameter must be a valid Netgen\\TagsBundle\\API\\Repository\\Values\\Tags\\Tag."
                    );
                }

                $tag = isset($parameters['tag']) ? $parameters['tag'] : $this->tagsService->loadTag($parameters['tagId']);
                unset($parameters['tag'], $parameters['tagId'], $parameters['viewType'], $parameters['layout']);

                return $this->generator->generate($tag, $parameters, $referenceType);
            }

            throw new InvalidArgumentException(
                "When generating a Tag route, either 'tag' or 'tagId' must be provided."
            );
        }

        throw new RouteNotFoundException('Could not match route');
    }
public function generate ( $ name , $ parameters = [ ] , $ referenceType = UrlGeneratorInterface :: ABSOLUTE_PATH ) { // Direct access to Tag if ( $ name instanceof Tag ) { return $ this -> generator -> generate ( $ name , $ parameters , $ referenceType ) ; } // Normal route name if ( $ name === self :: TAG_URL_ROUTE_NAME ) { if ( isset ( $ parameters [ 'tag' ] ) || isset ( $ parameters [ 'tagId' ] ) ) { // Check if tag is a valid Tag object if ( isset ( $ parameters [ 'tag' ] ) && ! $ parameters [ 'tag' ] instanceof Tag ) { throw new LogicException ( "When generating a Tag route, 'tag' parameter must be a valid Netgen\\TagsBundle\\API\\Repository\\Values\\Tags\\Tag." ) ; } $ tag = isset ( $ parameters [ 'tag' ] ) ? $ parameters [ 'tag' ] : $ this -> tagsService -> loadTag ( $ parameters [ 'tagId' ] ) ; unset ( $ parameters [ 'tag' ] , $ parameters [ 'tagId' ] , $ parameters [ 'viewType' ] , $ parameters [ 'layout' ] ) ; return $ this -> generator -> generate ( $ tag , $ parameters , $ referenceType ) ; } throw new InvalidArgumentException ( "When generating a Tag route, either 'tag' or 'tagId' must be provided." ) ; } throw new RouteNotFoundException ( 'Could not match route' ) ; }
Generates a URL for a tag, from the given parameters.

It is possible to directly pass a Tag object as the route name, as the ChainRouter allows it through ChainedRouterInterface

If $name is a route name, the "tag" key in $parameters must be set to a valid Netgen\TagsBundle\API\Repository\Values\Tags\Tag object.
"tagId" can also be provided.

If the generator is not able to generate the URL, it must throw the RouteNotFoundException as documented below.

@param string|\Netgen\TagsBundle\API\Repository\Values\Tags\Tag $name The name of the route or a Tag instance
@param mixed $parameters An array of parameters
@param int $referenceType The type of reference to be generated (one of the constants)

@throws \LogicException
@throws \Symfony\Component\Routing\Exception\RouteNotFoundException
@throws \InvalidArgumentException

@return string The generated URL
Generates a URL for a tag from the given parameters .