masev / settings-bundle

Masev SettingsBundle 将设置系统引入 eZ Publish 5.x,通过旧版管理员界面中的接口可以实现管理。

安装次数: 1,234

依赖项: 0

建议者: 0

安全: 0

星标: 5

关注者: 5

分支: 6

公开问题: 0

语言:JavaScript

3.0 2018-08-03 12:03 UTC

This package is not auto-updated.

Last update: 2024-09-29 22:05:29 UTC


README

Masev SettingsBundle 将设置系统引入 eZ Publish 5.x,通过旧版管理员界面中的接口(由 AngularJS 驱动)可以实现管理。所有设置都作为参数注入到 Symfony 容器中。它们与 eZ Publish Config Resolver 兼容,允许您为每个站点访问定义设置。

Screenshot of the UI

安装

步骤 1:使用 composer 下载 MasevSettingsBundle

在您的 composer.json 中添加 MasevSettingsBundle

{
    "require": {
        "masev/settings-bundle": "dev-master"
    }
}

现在运行以下命令让 composer 下载该组件

$ php composer.phar update masev/settings-bundle

Composer 将将组件安装到您的项目的 vendor/masev/settings-bundle 目录。

步骤 2:启用组件

在内核中启用组件

<?php
// ezpublish/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Masev\SettingsBundle\MasevSettingsBundle(),
    );
}

步骤 3:配置

编辑您的应用程序配置文件,提供连接到您的存储的信息,并列出包含可配置参数的组件。

Mysql 示例

# ezpublish/config/config.yml
masev_settings:
    mysql:
        host: 127.0.0.1
        user: root
        password: root
        dbname: mysettings
    varnish_purge:
        enabled: true (to enable varnish purge)
        purger_interface_id: mybundle.masev_settings.purger (id of service, it had to implement Masev\SettingsBundle\Purger\PurgerInterface    
    bundles: [ ... ]
    form:
        browse_limit: 500 (default 100) #change browse limit search
        
  • bundles : 包含可配置设置的组件列表

对于 Mysql 存储,您需要使用以下查询初始化设置表

CREATE TABLE `masev_settings` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `identifier` varchar(255) NOT NULL DEFAULT '',
  `value` TEXT NOT NULL,
  `scope` varchar(255) NOT NULL DEFAULT 'default',
  PRIMARY KEY (`id`),
  UNIQUE KEY `identifier_scope` (`identifier`,`scope`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

步骤 4:声明可配置设置

在您的组件中,在 <bundle_dir>/Resources/config/ 文件夹中创建一个名为 settings.xml 的文件。

<?xml version="1.0" encoding="UTF-8" ?>
<settings xmlns="http://william-pottier.fr/schema/settings"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://william-pottier.fr/schema/settings https://raw.github.com/wpottier/WizadSettingsBundle/master/Resources/schema/settings-1.0.xsd">

    <parameter key="category.sub_category.sender_name">
        <name>Email sender name</name>
        <default>Me</default>
    </parameter>

    <parameter key="category.sub_category.sender_email">
        <name>Email sender address</name>
        <default>me@my-site.com</default>
    </parameter>
    
    <parameter key="category.sub_category.message">
        <name>Message</name>
        <default></default>
        <form type="textarea" cols="30" rows="10"></form>
    </parameter>

</settings>

设置密钥必须具有类别和子类别名称,才能在旧版 UI 中正确显示。

清除 Symfony 缓存

php ezpublish/console cache:clear

在此步骤中,您应该能够在旧版 UI 中定义设置(eZ Publish 旧版管理员中的配置选项卡)。

步骤 5:查询设置

现在您已经定义了设置,可以使用 eZ Publish 配置解析器来查询它们。

// Get the 'category.sub_category.sender_name' settings in the current scope (i.e. current siteaccess)
$this->configResolver->getParameter('category.sub_category.sender_name', 'masev_settings');

// You can force siteaccess
$this->configResolver->getParameter('category.sub_category.sender_name', 'masev_settings', 'my_site_access');

在一个 twig 模板中,您可以使用 getMasevSettings() Twig 函数。