heimrichhannot / contao-utils-bundle
This bundle offers various utility functionality for the Contao CMS.
Installs: 100 088
Dependents: 87
Suggesters: 1
Security: 0
Stars: 8
Watchers: 5
Forks: 4
Open Issues: 2
Type:contao-bundle
Requires
- php: ^8.1
- ext-dom: *
- ext-simplexml: *
- contao/core-bundle: ^4.13 || ^5.0
- doctrine/dbal: ^2.13 || ^3.0
- psr/log: ^1.0 || ^2.0 || ^3.0
- symfony/config: ^5.4 || ^6.0
- symfony/event-dispatcher-contracts: ^1.0 || ^2.0 || ^3.0
- symfony/filesystem: ^5.4 || ^6.0
- symfony/http-foundation: ^5.4 || ^6.0
- symfony/http-kernel: ^5.4 || ^6.0
- symfony/string: ^5.2 || ^6.0
- twig/twig: ^3.0
Requires (Dev)
- contao/manager-plugin: ^2.0
- contao/test-case: ^4.0 || ^5.0
- heimrichhannot/contao-test-utilities-bundle: ^0.1
- php-coveralls/php-coveralls: ^2.0
- phpstan/phpstan: ^1.10
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^8.0 || ^9.0
- symfony/phpunit-bridge: ^5.4 || ^6.0
- v3.x-dev
- 3.6.0
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.0
- 3.0.0-beta3
- 3.0.0-beta2
- 3.0.0-beta
- v2.x-dev
- 2.239.2
- 2.239.1
- 2.239.0
- 2.238.3
- 2.238.2
- 2.238.0
- 2.237.0
- 2.236.0
- 2.235.3
- 2.235.2
- 2.235.1
- 2.235.0
- 2.234.1
- 2.234.0
- 2.233.1
- 2.233.0
- 2.232.0
- 2.231.0
- 2.230.1
- 2.230.0
- 2.229.4
- 2.229.3
- 2.229.2
- 2.229.1
- 2.228.2
- 2.228.1
- 2.228.0
- 2.227.1
- 2.227.0
- 2.226.1
- 2.226.0
- 2.225.0
- 2.224.2
- 2.224.1
- 2.224.0
- 2.223.3
- 2.223.2
- 2.223.1
- 2.223.0
- 2.222.1
- 2.222.0
- 2.221.2
- 2.221.1
- 2.221.0
- 2.220.1
- 2.220.0
- 2.219.0
- 2.218.1
- 2.218.0
- 2.217.2
- 2.217.1
- 2.217.0
- 2.216.1
- 2.216.0
- 2.215.2
- 2.215.1
- 2.215.0
- 2.214.0
- 2.213.0
- 2.212.1
- 2.212.0
- 2.211.0
- 2.210.1
- 2.210.0
- 2.209.6
- 2.209.5
- 2.209.4
- 2.209.3
- 2.209.2
- 2.209.1
- 2.209.0
- 2.208.1
- 2.207.0
- 2.206.1
- 2.206.0
- 2.205.3
- 2.205.2
- 2.205.1
- 2.205.0
- 2.204.2
- 2.204.1
- 2.204.0
- 2.203.3
- 2.203.2
- 2.203.1
- 2.203.0
- 2.202.4
- 2.202.3
- 2.202.2
- 2.202.1
- 2.202.0
- 2.201.0
- 2.200.0
- 2.199.1
- 2.199.0
- 2.198.0
- 2.197.0
- 2.196.3
- 2.196.2
- 2.196.1
- 2.196.0
- 2.195.1
- 2.195.0
- 2.194.1
- 2.194.0
- 2.193.1
- 2.193.0
- 2.192.2
- 2.192.1
- 2.192.0
- 2.191.0
- 2.190.0
- 2.189.0
- 2.188.10
- 2.188.9
- 2.188.8
- 2.188.7
- 2.188.6
- 2.188.5
- 2.188.4
- 2.188.3
- 2.188.2
- 2.188.1
- 2.188.0
- 2.187.0
- 2.186.0
- 2.185.0
- 2.184.1
- 2.184.0
- 2.183.0
- 2.182.1
- 2.182.0
- 2.181.4
- 2.181.3
- 2.181.2
- 2.181.1
- 2.181.0
- 2.180.2
- 2.180.1
- 2.180.0
- 2.179.0
- 2.178.2
- 2.178.1
- 2.178.0
- 2.177.6
- 2.177.5
- 2.177.4
- 2.177.3
- 2.177.2
- 2.177.1
- 2.177.0
- 2.176.1
- 2.176.0
- 2.175.2
- 2.175.1
- 2.175.0
- 2.174.0
- 2.173.1
- 2.173.0
- 2.172.1
- 2.172.0
- 2.171.5
- 2.171.4
- 2.171.3
- 2.171.2
- 2.171.1
- 2.171.0
- 2.170.0
- 2.169.2
- 2.169.1
- 2.169.0
- 2.168.2
- 2.168.1
- 2.168.0
- 2.167.0
- 2.166.0
- 2.165.0
- 2.164.2
- 2.164.1
- 2.164.0
- 2.163.0
- 2.162.0
- 2.161.1
- 2.161.0
- 2.160.0
- 2.159.1
- 2.159.0
- 2.158.0
- 2.157.3
- 2.157.2
- 2.157.1
- 2.157.0
- 2.156.1
- 2.156.0
- 2.155.2
- 2.155.1
- 2.155.0
- 2.153.0
- 2.152.1
- 2.152.0
- 2.151.1
- 2.151.0
- 2.150.0
- 2.149.0
- 2.148.1
- 2.148.0
- 2.147.0
- 2.146.0
- 2.145.0
- 2.144.0
- 2.143.0
- 2.142.0
- 2.141.1
- 2.141.0
- 2.140.0
- 2.139.0
- 2.138.0
- 2.137.0
- 2.136.1
- 2.136.0
- 2.135.2
- 2.135.1
- 2.135.0
- 2.134.0
- 2.133.0
- 2.132.0
- 2.131.0
- 2.130.0
- 2.129.0
- 2.128.1
- 2.128.0
- 2.127.0
- 2.126.0
- 2.125.0
- 2.124.0
- 2.123.1
- 2.123.0
- 2.122.0
- 2.121.0
- 2.120.1
- 2.120.0
- 2.119.4
- 2.119.3
- 2.119.2
- 2.119.1
- 2.119.0
- 2.118.0
- 2.117.2
- 2.117.1
- 2.117.0
- 2.116.0
- 2.115.0
- 2.114.0
- 2.113.0
- 2.112.0
- 2.111.0
- 2.110.0
- 2.109.0
- 2.108.0
- 2.107.0
- 2.106.0
- 2.105.0
- 2.104.4
- 2.104.3
- 2.104.2
- 2.104.1
- 2.104.0
- 2.103.1
- 2.103.0
- 2.102.0
- 2.101.1
- 2.101.0
- 2.100.2
- 2.100.1
- 2.100.0
- 2.99.1
- 2.99.0
- 2.98.3
- 2.98.2
- 2.98.1
- 2.98.0
- 2.97.2
- 2.97.1
- 2.97.0
- 2.96.0
- 2.95.0
- 2.94.0
- 2.93.0
- 2.92.0
- 2.91.2
- 2.91.1
- 2.91.0
- 2.90.3
- 2.90.2
- 2.90.1
- 2.90.0
- 2.89.2
- 2.89.1
- 2.89.0
- 2.88.0
- 2.87.4
- 2.87.3
- 2.87.2
- 2.87.1
- 2.87.0
- 2.86.2
- 2.86.1
- 2.86.0
- 2.85.0
- 2.84.1
- 2.84.0
- 2.83.1
- 2.83.0
- 2.82.1
- 2.82.0
- 2.81.2
- 2.81.1
- 2.81.0
- 2.80.1
- 2.80.0
- 2.75.1
- 2.75.0
- 2.74.0
- 2.73.0
- 2.72.0
- 2.71.0
- 2.70.2
- 2.70.1
- 2.69.1
- 2.69.0
- 2.68.2
- 2.68.1
- 2.68.0
- 2.67.2
- 2.67.1
- 2.67.0
- 2.66.1
- 2.66.0
- 2.65.2
- 2.65.1
- 2.65.0
- 2.64.1
- 2.64.0
- 2.63.0
- 2.62.0
- 2.61.0
- 2.60.8
- 2.60.7
- 2.60.6
- 2.60.5
- 2.60.4
- 2.60.3
- 2.60.2
- 2.60.1
- 2.60.0
- 2.59.2
- 2.59.1
- 2.59.0
- 2.58.0
- 2.57.0
- 2.56.1
- 2.56.0
- 2.55.0
- 2.54.0
- 2.53.0
- 2.52.0
- 2.51.1
- 2.51.0
- 2.50.0
- 2.49.3
- 2.49.2
- 2.49.1
- 2.49.0
- 2.48.0
- 2.47.1
- 2.47.0
- 2.46.2
- 2.46.1
- 2.46.0
- 2.45.0
- 2.44.2
- 2.44.1
- 2.44.0
- 2.43.0
- 2.42.1
- 2.42.0
- 2.41.0
- 2.40.1
- 2.40.0
- 2.39.0
- 2.38.0
- 2.37.0
- 2.36.0
- 2.35.0
- 2.34.3
- 2.34.2
- 2.34.1
- 2.34.0
- 2.33.0
- 2.32.0
- 2.31.0
- 2.30.4
- 2.30.3
- 2.30.2
- 2.30.1
- 2.30.0
- 2.29.2
- 2.29.1
- 2.29.0
- 2.28.10
- 2.28.9
- 2.28.8
- 2.28.7
- 2.28.6
- 2.28.5
- 2.28.4
- 2.28.3
- 2.28.2
- 2.28.1
- 2.28.0
- 2.27.0
- 2.25.5
- 2.25.4
- 2.25.3
- 2.25.2
- 2.25.1
- 2.25.0
- 2.24.1
- 2.24.0
- 2.23.1
- 2.23.0
- 2.22.4
- 2.22.3
- 2.22.2
- 2.22.1
- 2.22.0
- 2.21.0
- 2.20.1
- 2.20.0
- 2.19.0
- 2.18.4
- 2.18.3
- 2.18.2
- 2.18.1
- 2.18.0
- 2.17.0
- 2.16.2
- 2.16.1
- 2.16.0
- 2.15.2
- 2.15.1
- 2.15.0
- 2.14.1
- 2.14.0
- 2.13.0
- 2.12.1
- 2.12.0
- 2.11.0
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.1
- 2.9.0
- 2.8.8
- 2.8.7
- 2.8.6
- 2.8.5
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.9
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.16
- 2.0.15
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feature/entity_finder_forms
- dev-feature/enhance_entity_finder_article_search
- dev-feature/backend_ui_util
- dev-feature/facade
- dev-feature/psalm
This package is auto-updated.
Last update: 2024-12-09 10:48:27 UTC
README
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 ;
Entity Finder
The entity finder is a command to search for any contao entities in your database.
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