netzmacht / contao-dev-tools
dev-master / 1.0.x-dev
2015-01-12 14:11 UTC
Requires
- php: >=5.4
- contao-community-alliance/dependency-container: ~1.6
- contao/core: >=3.1,<3.5-dev
Requires (Dev)
- henrikbjorn/phpspec-code-coverage: ~0.2
- netzmacht/contao-build-tools: 1.0.x-dev
- phpspec/phpspec: 2.1.x-dev
This package is auto-updated.
Last update: 2022-02-01 12:42:59 UTC
README
此库为开发Contao CMS时解决常见任务提供工具。
安装
您可以使用Composer安装此库。
$ php composer.phar require netzmacht/contao-dev-tools:~1.0
功能
DCA相关功能
####切换图标回调
此库包含一个通用的切换状态图标回调。
<?php // dca/tl_custom.php $GLOBALS['TL_DCA']['tl_custom']['fields']['published']['button_callback'] = Netzmacht\Contao\DevTools\Dca::createToggleIconCallback( 'tl_custom', // The database table. 'published', // the state column false, // Inverse the state. Set to true for invisible='' columns 'invisible.gif' // Disabled icon. If not set, icons are transformed from edit.gif to edit_.gif )
####将模型转换为选项
使用Contao模型的一个标准任务是将其转换为选择列表或复选框菜单的选项。Dev-Tools为您简化了这一过程。
- 将集合转换为选项数组。
- 使用回调自定义标签。
- 按第三列/回调值分组值。
<?php public function yourOptionsCallback() { $collection = \PageModel::findAll(); // Empty collections by Contao are NULL. The OptionsBuilder handles is correctly. return Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder::fromCollection($collection, 'id', 'name') ->groupBy('type') ->getOptions(); } ```php ###Dependency injection Contao does not provide any help for dependency injection. If you need some dependencies from the [dependency container](https://github.com/contao-community-alliance/dependency-container) you can use this Trait: ```php class YourContentElement extends \ContentElement { use Netzmacht\Contao\DevTools\ServiceContainerTrait; private $service; public function __construct($model) { parent::__construct($model); $this->service = $this->getService('your-required-service'); } }
要求
- 需要PHP 5.4。
- 支持Contao 3.2 - 3.4。
- 需要contao-community-alliance/dependency-container ~1.6。