Message-ID: <626356784.3034.1485851709056.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3033_766031375.1485851709056" ------=_Part_3033_766031375.1485851709056 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Cross-siteaccess links

Cross-siteaccess links

When using the multisite feature, it is sometimes usefu= l to be able to generate cross-links between the different= sites.
This allows you to link different resources referenced in the s= ame content repository, but configured independently with different tree ro= ots.

Twig example
=20
 {# Linking a location #}=20
<a href=3D"{{ url( 'ez_urlalias', {'locationId': 42, 'siteaccess': 'some=
_siteaccess_name'} ) }}">{{ ez_content_name( content ) }}</a>

{# Linking a regular route #}=20
<a href=3D"{{ url( "some_route_name", {"siteaccess": "some_siteaccess_na=
me"} ) }}">Hello world!</a>
=20
See=20 ez_u= rlalias documentation page, for more information about linking to a Loc= ation

 

 

PHP example
=20
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller as BaseController;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class MyController extends BaseController
{
    public function fooAction()
    {
        // ...

        $location =3D $this->getRepository()->getLocationService()-&g=
t;loadLocation( 123 );
        $locationUrl =3D $this->generateUrl(
            $location,
            array( 'siteaccess' =3D> 'some_siteaccess_name' ),
            UrlGeneratorInterface::ABSOLUTE_PATH
        );

        $regularRouteUrl =3D $this->generateUrl(
            'some_route_name',
            array( 'siteaccess' =3D> 'some_siteaccess_name' ),
            UrlGeneratorInterface::ABSOLUTE_PATH
        );

        // ...
    }
}
=20
 

Important

As siteaccess matchers can involve hosts and ports, it is=20 highly recommended to generate cross-siteaccess links in a= n absolute form (e.g. using=20 url() Twig helper).

To implement this feature, a new VersatileMatcher was added= to allow siteaccess matchers to be able to reverse-match.
All= existing matchers implement this new interface, except the Regexp based ma= tchers which have been deprecated.

The siteaccess router has been added a matchByName() method= to reflect this addition. Abstract URLGenerator and DefaultRouter have been updated as well.

Note

Siteaccess router public methods have also been extracted to a new interfac= e,=20 SiteAccessRouterInterface.

 

------=_Part_3033_766031375.1485851709056--