heimrichhannot/contao-list_widget 问题修复 & 功能扩展

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

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

heimrichhannot/contao-list_widget

Composer 安装命令:

composer require heimrichhannot/contao-list_widget

包简介

This simple module offers an input type for displaying a list of entities definable by a callback function.

README 文档

README

For contao 4 please use List Widget Bundle

This simple module offers functionality for displaying a list in the Contao backend (either as a dca field or in a backend module).

For visualization the javascript library DataTables is used.

alt text

Features

  • inputType "listWidget" for usage as a dca field
  • convenient functions for integrating a list in your backend module
  • the list can display either model data or even arbitrary arrays
  • support for datatables javascript library
    • filter the table
    • search the table
    • sort the table
  • support for ajax reloading data using datatables -> currently only working for contao models since SQL-commands like LIMIT are used

Technical instructions

Usage as a widget in a dca field

Use the inputType "listWidget" for your field.

'someField' => [
    'label'     => &$GLOBALS['TL_LANG']['tl_my_dca']['someField'],
    'exclude'   => true,
    'inputType' => 'listWidget',
    'eval'      => [
        'listWidget' => [
            'ajax'                   => true,
            'ajaxConfig'             => [
                'load_items_callback' => ['SomeClass', 'loadItems']
            ],
            'header_fields_callback' => function ()
            {
                $arrHeaderFields = [];

                foreach (['academicTitle', 'additionalTitle', 'gender', 'lastname', 'email'] as $strField)
                {
                    $arrHeaderFields[$strField] = \HeimrichHannot\Haste\Dca\General::getLocalizedFieldname($strField, 'tl_dca');
                }

                return $arrHeaderFields;
            },
            'table'                  => 'tl_dca'
        ]
    ]
]

Usage in a module

Add the following code e.g. in the generate() method of your BackendModule:

static::$arrListConfig = [
    'identifier' => 'module_' . $this->id,
    'table' => 'tl_dca',
    'ajax' => true,
    'ajaxConfig' => [
        'load_items_callback' => function($arrConfig, $arrOptions = [], $objContext = null, $objDc = null) {
            return $this->loadItems($arrConfig, $arrOptions, $objContext, $objDc);
        },
        'prepare_items_callback' => function($objItems) {
            return $this->parseNewsletters($objItems);
        },
    ],
    'columns' => static::getColumns(),
    'language' => static::getLanguage()
];

static::$arrListConfig = ListWidget::prepareConfig(static::$arrListConfig, $this);

ListWidget::initAjaxLoading(static::$arrListConfig);

Call this in your module's compile method:

ListWidget::addToTemplate($this->Template, static::$arrListOptions);

Copy the content of list_widget.html5 into your module's template.

Example load_items_callback

Here you can see an example for overriding the core behavior of loadItems():

public static function loadItemsNew($arrConfig, $arrOptions = [], $objContext = null, $objDc = null)
{
    // set an initial filter using the contao options array
    $arrOptions = [
        'table'   => $arrConfig['table'],
        'columns' => $arrConfig['columns'],
        // filtering
        'column'  => 'pid',
        'value'   => $objDc->id
    ];

    // the rest of the function should also be called
    return ListWidget::loadItems($arrConfig, $arrOptions, $objContext, $objDc);
}

Config (same structure for DCA -> eval -> listWidget and shortcut functions)

Name Possible value Description
identifier string Needed for distinguishing requests from multiple list widget implementations, e.g. 'module_' . $this->id
header_fields array Must return an array containing the header fields. The keys must match the keys of the arrays/objects in items/items_callback.
header_fields_callback callback array, function closure Must return an array containing the header fields. The keys must match the keys of the arrays/objects in items/items_callback.
items array Must return an array containing the items to be displayed. The item keys must match those in header_fields/header_fields_callback.
items_callback callback array, function closure Must return an array containing the items to be displayed. The item keys must match those in header_fields/header_fields_callback.
table string (e.g. "tl_dca") This value is needed for useDbAsHeader and ajax handling
useDbAsHeader boolean Set to true if the header should contain all fields of a certain database entity ("table" is used)
template string Specify a custom template
language array Specify custom localizations (see ListWidget::getLanguage() for details)
language_callback callback array, function closure Specify custom localizations (see ListWidget::getLanguage() for details)
ajax boolean Set to true if ajax reloading should take place (no need for items_callback in this case)
ajaxConfig -> load_items array Override this if custom model options or methods are needed (see ListWidget::loadItems() for details)
ajaxConfig -> load_items_callback callback array, function closure Override this if custom model options or methods are needed (see ListWidget::loadItems() for details)
ajaxConfig -> prepare_items array Override this if custom data preparation is needed (see ListWidget::prepareItems() for details)
ajaxConfig -> prepare_items_callback callback array, function closure Override this if custom data preparation is needed (see ListWidget::prepareItems() for details)

Callbacks

Name Arguments Expected return value Description
headerFields_callback $objDc, $arrDca, $objWidget array containing field and label pairs (['field1' => 'fieldLabel1', 'field2' => 'fieldLabel2', ...]) This callback must return the headerFields to be displayed in the list. Array keys need to be the keys in items_callback (see list_widget.html5 for explanation).
items_callback $objDc, $arrDca, $objWidget array of entity arrays ([['field1' => 'value1', 'field2' => 'value2'], ...]) This callback must return the items to be displayed in the list
load_callback $arrOptions, [], $objDc, $arrDca, $objWidget data array (see ListWidget::loadItems for more details) Override this method if custom model options or methods are needed
prepare_items_callback $objItems, $arrListOptions, $arrOptions, $objDc, $arrDca, $objWidget data array (see ListWidget::prepareItems for more details) Override this method if custom data preparation is needed

heimrichhannot/contao-list_widget 适用场景与选型建议

heimrichhannot/contao-list_widget 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.62k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 heimrichhannot/contao-list_widget 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2016-12-13