承接 tienvx/ux-collection-js 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tienvx/ux-collection-js

Composer 安装命令:

composer require tienvx/ux-collection-js

包简介

Symfony UX integration for collection form type

README 文档

README

UX collection JS is a Symfony bundle providing Symfony UX integration for collection form type with the help from Symfony Collection JS library.

Screenshots

Bootstrap 3

Screenshot Bootstrap 3

Bootstrap 5

Screenshot Bootstrap 5

EasyAdmin

Screenshot EasyAdmin

Installation

UX Collection JS requires PHP 7.4+ and Symfony 4.4+.

Install this bundle using Composer and Symfony Flex:

composer require tienvx/ux-collection-js:^1.0

# Don't forget to install the JavaScript dependencies as well and compile
yarn add --dev '@symfony/stimulus-bridge@^2.0.0'
yarn install --force
yarn encore dev

Usage

Symfony

Use the new CollectionType class defined by this bundle:

// ...
use Tienvx\UX\CollectionJs\Form\CollectionJsType;

class PostType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // ...
            ->add('authors', CollectionJsType::class, [
                'entry_type' => TextType::class,
                'prototype' => true,
                'allow_add' => true,
                'allow_delete' => true,
                'allow_move_up' => true,
                'allow_move_down' => true,
                'call_post_add_on_init' => true,
            ])
            // ...
        ;
    }

    // ...
}

Then you need to set the form theme:

# config/packages/twig.yaml
twig:
    form_themes:
      - '@CollectionJs/bootstrap_5_layout.html.twig'

Available themes:

  • @CollectionJs/bootstrap_5_layout.html.twig
  • @CollectionJs/bootstrap_4_layout.html.twig
  • @CollectionJs/bootstrap_3_layout.html.twig

Easyadmin

Create webpack entry:

// webpack.config.js
.addEntry('stimulus', './assets/stimulus.js')

Then create that javascript file:

// assets/stimulus.js

// start the Stimulus application
import './bootstrap';

Use the new collection type in the easyadmin controller:

namespace App\Controller\EasyAdmin;

use Tienvx\UX\CollectionJs\Form\CollectionJsType;

class FormFieldReferenceController extends AbstractCrudController
{
    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            // ...
            ->setFormThemes(['@EasyAdmin/crud/form_theme.html.twig', '@CollectionJs/bootstrap_5_layout.html.twig']);
    }

    public function configureFields(string $pageName): iterable
    {
        yield CollectionField::new('collectionSimple', 'Collection Field (simple)')
                ->setFormType(CollectionJsType::class)
                ->setFormTypeOptions([
                    'entry_type' => CollectionSimpleType::class,
                    'allow_add' => true,
                    'allow_delete' => true,
                    'allow_move_up' => true,
                    'allow_move_down' => true,
                    'call_post_add_on_init' => true,
                ])
                ->addWebpackEncoreEntries('stimulus');
    }
}

Configuration

Config name Description Type Default
prototype CollectionJsType form type need prototype = true Boolean true
allow_add Allow show/hide 'Add a new item' button Boolean false
allow_delete Allow show/hide 'Remove the item' button Boolean false
allow_move_up Allow show/hide 'Move item up' button Boolean false
allow_move_down Allow show/hide 'Move item down' button Boolean false
call_post_add_on_init Trigger 'ux-collection-js:post-add' event on init Boolean false

Stimulus Events

Namespace Event Description Detail
ux-collection-js post-add After an item is added new_elem, context, index
ux-collection-js post-delete After an item is removed delete_elem, context, index
ux-collection-js post-up After an item is moved up elem, switched_elem, index
ux-collection-js post-down After an item is moved down elem, switched_elem, index

Example

// SomeController.php
$form = $this->createFormBuilder($task)
    ->add('some_field', SomeType::class, [
        'attr' => [
            'data-controller' => 'items',
            'data-action' => 'ux-collection-js:post-add->items#postAdd ux-collection-js:post-delete->items#postDelete ',
        ],
    ])
    ->getForm();
// items_controller.js
import { Controller } from 'stimulus';

export default class extends Controller {
    postDelete(event) {
        const { delete_elem, context, index } = event.detail;
    }

    postAdd(event) {
        const { new_elem, context, index } = event.detail;
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

tienvx/ux-collection-js 适用场景与选型建议

tienvx/ux-collection-js 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.78k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2021 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony-ux」 「ux-collection-js」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 tienvx/ux-collection-js 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-02