cubetools/cube-custom-fields-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cubetools/cube-custom-fields-bundle

Composer 安装命令:

composer require cubetools/cube-custom-fields-bundle

包简介

Custom fields in forms and entities

README 文档

README

Add custom fields to forms and entities (installation specifig).

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require cubetools/cube-custom-fields-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new CubeTools\CubeCustomFieldsBundle\CubeToolsCubeCustomFieldsBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configure the bundle

Add the routes in app/config/routing.yml of your project.

    ...
cube_custom_fields:
    resource: "@CubeCustomFieldsBundle/Resources/config/routing/all.yml"

Then configure the bundle in app/config/config.yml of your project.

imports:
    ...
    { resource: custom_fields.yml }
    # or to ignore when not existing or invalid { resource: custom_fields.yml, ignore_errors: true }

app/config/custom_fields.yml

cube_custom_fields:
    entities:
        XxBundle\Entities\Entity1:
            field_id1:
                field_type: SomeFormType
                     # like Symfony\Component\Form\Extension\Core\Type\[TextType|SelectType|DateTimeType]|Symfony\Bridge\Doctrine\Form\Type\EntityType]
                label: 'label.for.a_field'
                form_options:
                     # any form option
                     label: label for in form # overwrites label from above
            field_idB:
                type: Symfony\Component\Form\Extension\Core\Type\SelectType
                label: label.select.something
                form_options:
                    choices:
                        label1: value1
                        ...
        SomeTool\YyBundle\Entity\Entity2:
            responsibles: # this links as m:n to an existing entity type
                type: Symfony\Bridge\Doctrine\Form\Type\EntityType
                label: 'Responsible Persons'
                field_options:
                    required: false
                    multiple: true
                    class: 'AppBundle:User'
                    attr:
                        class: select2
                        placeholder: Select responsible persons
            selections: # this links to the custom fields table itself, giving access to all TextCustomField entities with fieldId = predef_1
                type: Symfony\Bridge\Doctrine\Form\Type\EntityType
                label: 'Predefined select options'
                filter: predef_1 # this is the name of the referred custom field
                field_options:
                    required: false
                    multiple: false
                    class: 'CubeTools\CubeCustomFieldsBundle\Entity\TextCustomField'
                    attr:
                        class: select2
                        placeholder: Select from set of options
            owner: # special case for ajax retrievable select2 boxes (Using Tetranz\Select2EntityBundle)
                type: Tetranz\Select2EntityBundle\Form\Type\Select2EntityType # contains the class of the form type used
                label: 'Owned by'
                filters: # this can be used to filter for specific fields on the target entity (e.g. only activated users etc.). Note that this is not the same field as for "normal" entity type custom fields (it is "filter" there).
                    enabled: 1
                field_options:
                    required: false
                    multiple: false
                    class: 'AppBundle:User' # contains the class of the objects visible to the user (the REAL entities)
                    minimum_input_length: 0
                    page_limit: 10
                    scroll: true
                    allow_clear: false
                    delay: 250
                    cache: true
                    cache_timeout: 500
                    placeholder: Please select
                    language: de
                    attr:
                        style: width:100%
                        data-role: none
                        any_none: any:{not empty},none:{empty} # strings used to identify empty or non-empty custom fields in filters
    # access_rights_table: 'XxBundle:AccessEntity'

Step X: link custom fields to entities

Allow to link custom fields to your entity.

class Xxx
{
    use \CubeTools\CubeCustomFieldsBundle\CustomFieldsEntityHook;
}

Step X: show fields in the forms

Add the custom fields to your forms.

class XxxType extends FormType
{
    ...
    public function buildForm(...)
    {
        ...
        $customFieldsService = $options['customFieldsService']; // or configure your form as a service
        $customFieldsService->addCustomFields($form);
    }
    ...
}

class XzyController extends Controller
{
    ...
    public function zxyAction(CubeTools\CubeCustomFieldsBundle\Form\CustomFieldsFormService $customFieldsService)
    {
        // or $customFieldsService = $this->get('cube_custom_fields.form_fields');
        $form = $this->createForm(XxxType::class, null, array('customFieldsService' => $customFieldsService;
        ...
    }

Step X: display the fields

import dynamicFields.macro.twig as dynFld

...
{{ dynFld.title_column(entities) }}
...
{{ dynFld.filter_column(entities) }}
...
{% for(entity in entites) %}
    ...
    {{ dynFld.value_column(entity) }}

cubetools/cube-custom-fields-bundle 适用场景与选型建议

cubetools/cube-custom-fields-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.48k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 cubetools/cube-custom-fields-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 cubetools/cube-custom-fields-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 cubetools/cube-custom-fields-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.48k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-12