eZ Platform Discussions

Administer the configuration of each site

version2

#1

In the older version of eZ (4.?) there was a’design’ entry in the main menu of the BO.
In the submenu, the link “Appearance” made it possible to edit an object of type Appearance linked to the siteaccess and which made it possible to modify the header, footer, menu (according to the configuration).
In short, there was a place to store these manageable configuration items for the whole site.

I don’t find this feature in more recent versions of eZ. (since the 5)

I need this feature for a multi-site.
Each site must have its own conf.

For the moment I will create a ContentType’site_setting’ and I will create an instance under someone of the landingpage of the siteaccess.
In the pagelayout rendering I will put a twig helper to celebrate the first site_setting of the access site.

But I don’t find it very clean…

How would you do that?


#2

We are doing it in a similar way, not much you can do if you need to expose editing of those settings to some editor.


#3

As @gof said, we’re using something similar, but instead of fetching the first content we find under a specific subtree, we create those objects in media section and use configuration to exactly say what content ID to use for each of the siteaccesses.


#4

Great.

How can I access current siteaccess then ezpublish.system.my_siteaccess.content.tree_root.location_id from my twig function?

(Or any other config key.)

class MyTwigExtension extends \Twig_Extension
{

    public function getFunctions() {
        return array(
            new \Twig_SimpleFunction('get_site_settings', [$this, 'getSiteSettings'] ),
        );
    }

    public function getSiteSettings()
    {
        $tree_root_location_id = $this->container->getParameter('ezpublish.system.my_siteaccess.content.tree_root.location_id'); //: 9756)
     // ...
    }
}

#5

This information is available in the global twig variables present in the template… It is enough to transmit it:)

{% set site_settings = get_site_settings(ezpublish.siteaccess, ezpublish.rootLocation) %}
public function getSiteSettings(SiteAccess $siteaccess, Location $rootLocation)

#6

@remy_php There is a dedicated service in eZ Platform called config resolver (with service ID ezpublish.config.resolver) which will do that, and it is recommended to use it instead of fetching parameters from container directly. Something like this:

use eZ\Publish\Core\MVC\ConfigResolverInterface;

class MyTwigExtension extends \Twig_Extension
{
    private $configResolver;

    public function __construct(ConfigResolverInterface $configResolver)
    {
        $this->configResolver = $configResolver;
    }

    public function getFunctions() {
        return array(
            new \Twig_SimpleFunction('get_site_settings', [$this, 'getSiteSettings'] ),
        );
    }

    public function getSiteSettings()
    {
        $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id'); // 9756

        // ....
    }
}

#7

Indeed it is much better like that :wink:

By the way; How to recover the current siteaccess?


#8

If you’re asking in context of config resolver, you don’t need to. Config resolver gives you the configuration specific to current siteaccess.

Elsewhere, you can get the current siteaccess from the request:

$siteAccessName = $request->attributes->get('siteaccess')->name;