PHP code example of heimrichhannot / contao-utils-bundle
1. Go to this page and download the library: Download heimrichhannot/contao-utils-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
heimrichhannot / contao-utils-bundle example snippets
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>';
}
}
# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\AuthorField;
AuthorField::register('tl_example');
# 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
;
# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\DateAddedField;
DateAddedField::register('tl_example');
# 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
;
twig
{{ user.email|anonymize_email }}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.