20steps/drupal-bundle

将 Symfony2 与 Drupal 集成

安装: 19

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 5

分支: 20

类型:symfony-bundle

1.0.0 2015-08-31 16:40 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:08:54 UTC


README

该扩展包深度集成了20steps的Bricks,包括与Drupal7的集成以及反之亦然。这是在不修改Drupal核心的情况下完成的。

当此扩展包激活时,Symfony 3控制台将自动加载Drupal 7.x库。因此,您可以在Symfony 3命令中使用Drupal库。

安装

下载20steps的Bricks Drupal 7版本

配置

根据您的需求调整etc/config/cms.yml文件

parameters:
    session.flashbag.class:       Ekino\Bundle\DrupalBundle\Port\DrupalFlashBag
    session.attribute_bag.class:  Ekino\Bundle\DrupalBundle\Port\DrupalAttributeBag

framework:
    # ... configuration options
    session:
        # ... configuration options
        storage_id:     ekino.drupal.session.storage

ekino_drupal:
    root:          %kernel.root_dir%/../web
    logger:        ekino.drupal.logger.watchdog
    strategy_id:   ekino.drupal.delivery_strategy.symfony
    # attach a security token to the following provider keys
    provider_keys: [main, admin]

    # not required
    entity_repositories:
        # 3 equivalent examples of configuration:
        - { bundle: page }
        - { type: node, bundle: page }
        - { type: node, bundle: page, class: Ekino\Bundle\DrupalBundle\Entity\EntityRepository }
        # you can also define an entity repository:
        - { type: node, class: Application\Ekino\Bundle\DrupalBundle\Entity\Node\NodeRepository }

    # switch to true if you want to prefix the name of Symfony tables
    table_prefix:
        enabled: false
        prefix:  symfony__
        exclude: [users]

    # optional
    session:
        refresh_cookie_lifetime: true # default value: false

# declare 2 required mapping definition used by Drupal
doctrine:
    dbal:
        driver:   %database_driver%
        dbname:   %database_name%
        user:     %database_user%
        host:     %database_host%
        port:     %database_port%
        password: %database_password%
        charset:  UTF8

        mapping_types:
            longblob: object
            blob: object

        # Tips: this allows Doctrine to consider only tables starting with
        # "symfony__" during a migration generation.
        # Think to add Doctrine migrations table here or configure it in
        # the doctrine_migrations section (table_name)
        schema_filter: ~^(symfony__|migration_versions)~

该扩展包包含3种交付策略

  • ekino.drupal.delivery_strategy.background: Drupal从不返回响应,Symfony则返回
  • ekino.drupal.delivery_strategy.drupal: 即使页面是404,Drupal也始终返回响应
  • ekino.drupal.delivery_strategy.symfony: 只有当页面不是404时,Drupal才返回响应

(可选)部分 entity_repositories 允许您轻松与Drupal 7.x API交互,以检索内容并在Symfony代码中处理。配置提供了默认值

  • 默认实体类型是 node
  • 默认仓库类是 Ekino\Bundle\DrupalBundle\Entity\EntityRepository,您可以自由配置自己的

更新查询

UPDATE users SET `emailCanonical` = `mail`, `usernameCanonical` = `name`, `roles` = 'b:0;';

用法

可以从Drupal内部使用Symfony服务

<?php
function drupal_foo_function() {
    $result = symfony_service('reusage_service')->foo();

    // do some stuff with $result
}

安全性

您可以使用带有前缀 PERMISSION_DRUPAL_ 的Drupal权限来保护Symfony路由,例如

security:
    role_hierarchy:
        # ...

    firewalls:
        # ...

    access_control:
        - { path: ^/symfony/admin, role: PERMISSION_DRUPAL_ACCESS_ADMINISTRATION_PAGES }

PERMISSION_DRUPAL_ACCESS_ADMINISTRATION_PAGES 翻译为 "访问管理页面" 并与 user_access 和全局Drupal用户一起使用

如果您想使用您自己的 "个人访问" 权限,例如,使用角色 PERMISSION_DRUPAL_PERSONAL_ACCESS。

限制

  • 无法使用Symfony原生类来管理会话,因为Drupal初始化了自己的会话处理器,并且无法更改这一点。

预览

如果安装成功完成,欢迎页面看起来像这样

Screenshot

您可以看到底部的Symfony Web调试工具栏 ;-).