承接 heimrichhannot/contao-utils-bundle 相关项目开发

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

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

heimrichhannot/contao-utils-bundle

Composer 安装命令:

composer require heimrichhannot/contao-utils-bundle

包简介

This bundle offers various utility functionality for the Contao CMS.

README 文档

README

example branch parameter Coverage Status

Hi, you're looking on a very new version of utils bundle, version 3! See CHANGELOG.md for more information! If you're looking for version 2, please check the v2 branch.

Utils Bundle is a collection of many small helper to solve repeating task. At the center there is a utils service allow access to all util function. In addition, there are DcaField helpers, the Entity finder command and some nice twig filters.

Features

  • Utils-Service - A service allow access all bundled utils functions.
  • DcaField registration - An nice api to add typical dca fields to your dca fields without repeating yourself or annoying order restrictions.
    • AuthorField - Add an author field with automatic filling of the default value and optional frontend member support
    • DateAddedField - Add a date added field to store the date of entity creation
  • Entity Finder - A command to search for any contao entities in your database.
  • Twig Filters

Install

Just install it via composer or contao manager:

composer require heimrichhannot/contao-utils-bundle

Usage

Utils service

The Utils service is the core functionality of this bundle. It provides access to a lot of util functions help solving recurring tasks. It's build as one service from which you can access all utils services. The utils service is best used with dependency injection, but is also available from the service container as public service for usage in legacy code. You can check the API Documentation to see all available functions.

use HeimrichHannot\UtilsBundle\Util\Utils;

/**
 * A class containing examples usage of utils services. Please don't expect it to be useful :)
 */
class MyClass{
   /** @var Utils */
   protected $utils;
    
   public function __construct(Utils $utils) {
       $this->utils = $utils;
   }
   
   public function someActions(): bool {
        $dcaFields = $this->utils->dca()->getDcaFields('tl_content');
        $this->utils->array()->removeValue('headline', $dcaFields);
        foreach ($dcaFields as $dcaField) {
            echo $this->utils->string()->camelCaseToDashed($dcaField);
        }
        
        $rootPageModel = $this->utils->request()->getCurrentRootPageModel();
        echo $this->utils->anonymize()->anonymizeEmail($rootPageModel->adminEmail);
        
        $groupUsers = $this->utils->user()->findActiveUsersByGroup([1,2]);
        $this->utils->url()->addQueryStringParameterToUrl('user='.$groupUsers[0]->username, 'https://example.org');
        
        if ($this->utils->container()->isBackend()) {
            $where = $this->utils->database()->createWhereForSerializedBlob('dumbData', ['foo', 'bar']);
            $model = $this->utils->model()->findOneModelInstanceBy('tl_content', [$where->createAndWhere()], [$where->values]);
            echo '<div '.$this->utils->html()->generateAttributeString($model->getHtmlAttributes()).'></div>';
        }
}

Static Utils

Static helper methods that do not need to be injected are provided by the SUtils locator.

At this time, the following static helpers are available:

use HeimrichHannot\UtilsBundle\StaticUtil\SUtils;

SUtils::array()->insertBeforeKey($array, $keys, $newKey, $newValue);
SUtils::array()->insertAfterKey($array, $key, $value, $newKey = null, $options = []);
$foundAndRemoved = SUtils::array()->removeValue($value, $array);

SUtils::class()->hasTrait($class, $trait);

Dca Fields

The bundle provides some common dca fields that can be used in your dca files.

Author field

Add an author field to your dca. It will be initialized with the current backend user. On copy, it will be set to the current user.

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\AuthorField;

AuthorField::register('tl_example');

You can pass additional options to adjust the field:

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\AuthorField;

AuthorField::register('tl_example')
    ->setType(AuthorField::TYPE_MEMBER) // can be one of TYPE_USER (default) or TYPE_MEMBER. Use TYPE_MEMBER to set a frontend member instead of a backend user
    ->setFieldNamePrefix('example') // custom prefix for the field name
    ->setUseDefaultLabel(false) // set to false to disable the default label and set a custom label in your dca translations
    ->setExclude(false) // set the dca field exclude option
    ->setFilter(false) // set the dca field filter option
    ->setSearch(false) // set the dca field search option
    ->setSorting(false) // set the dca field sorting option
;

Date added field

Add a date added field to your dca. It will set a timestamp on create or copy.

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\DateAddedField;

DateAddedField::register('tl_example');

You can pass additional options to adjust the field:

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\DateAddedField;

DateAddedField::register('tl_example')
    ->setExclude(false) // set the dca field exclude option
    ->setFilter(false) // set the dca field filter option
    ->setSearch(false) // set the dca field search option
    ->setSorting(true) // set the dca field sorting option
;

Alias field

Add an alias field to your dca. Set the alias if the alias field is empty on save and check for duplicates.

use HeimrichHannot\UtilsBundle\Dca\AliasField;

AliasField::register('tl_example');

You can pass additional options to adjust the field:

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\AliasField;

AliasField::register('tl_example')
    AliasField::register('tl_md_newsletter')
    ->setAliasExistCallback([NewsletterCallbackListener::class, 'checkAliasExist']) // set a custom alias exist callback
    ->setExclude(false) // set the dca field exclude option
    ->setSearch(false) // set the dca field search option
    ->setFilter(false) // set the dca field filter option
    ->setSorting(true) // set the dca field sorting option
    ->setFlag(null) // set the dca field flag option
;

Entity Finder

The entity finder is a command to search for any contao entities in your database.

Entity finder

Twig Filters

This bundle contains currently one twig filter:

anonymize_email

Returns an anonymized email address. max.muster@example.org will be max.****@example.org

{{ user.email|anonymize_email }}

Notes

Backwards Compatibility Promise

We try our best to keep this bundle backwards compatible and follow the principle of semantic versioning.

Following aspects are not covered by BC promise:

  • Using Utils classes direct instead from Utils service. This is not officially supported and may break your application due internal changes.
  • Classes marked as @internal or @experimental

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 119.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 11
  • 依赖项目数: 88
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2018-01-17