heimrichhannot / contao-progress-bar-widget-bundle
This bundle offers a dynamic progress bar widget for the Contao CMS.
Installs: 908
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.2||^8.0
- contao/core-bundle: ^4.9
- heimrichhannot/contao-utils-bundle: ^2.204
Requires (Dev)
- contao/manager-plugin: ^2.0
- contao/test-case: 1.1.*
- friendsofphp/php-cs-fixer: ^2.2
- php-http/guzzle6-adapter: ^1.1
- php-http/message-factory: ^1.0.2
- phpunit/php-token-stream: ^1.4|^2.0|^3.0
- phpunit/phpunit: >=6.0 <6.5
- phpunit/phpunit-mock-objects: ^4.0|^5.0
- satooshi/php-coveralls: ^2.0
- symfony/phpunit-bridge: ^3.2
This package is auto-updated.
Last update: 2024-11-16 14:57:11 UTC
README
This bundle offers a dynamic progress bar widget for the Contao CMS.
Features
- adds a progress bar widget (currently for the backend only) for a given database record
- ajax support (self-auto-updating)
- also display the progress in numbers
Impressions
The progress bar widget included in an example data container array
Installation
- Install via composer:
composer require heimrichhannot/contao-progress-bar-widget-bundle
.
Usage
- Create the field in the desired data container array (DCA) as usual:
'importProgress' => [ 'inputType' => 'huhProgressBar', 'eval' => [ // an introduction text for the widget (mandatory) 'description' => $GLOBALS['TL_LANG']['tl_entity_import_config']['reference']['importProgressDescription'], // only show the progress bar but not the numbers below (optional, default false) 'hideNumbers' => false, // hide skipped items from the numbers section (optional, default false) 'hideSkippedItems' => false ] ],
- The progress is passed via an event listener for the event
LoadProgressEvent
. Register an event listener (or subscriber) as usual in symfony:use HeimrichHannot\ProgressBarWidgetBundle\Event\LoadProgressEvent; use HeimrichHannot\ProgressBarWidgetBundle\Widget\ProgressBar; use Terminal42\ServiceAnnotationBundle\Annotation\ServiceTag; /** * @ServiceTag("kernel.event_listener", event="huh.progress_bar_widget.event.load_progress") */ class LoadProgressListener { public function __invoke(LoadProgressEvent $event) { if (null === ($record = MyModel::findByPk($event->getId()))) { return; } // map the record's state field to the progress bar's expectations // of course you can decide yourself in which cases you'd like to pass which state switch ($record->state) { case 'success': $state = ProgressBar::STATE_SUCCESS; $class = 'tl_confirm'; break; case 'error': $state = ProgressBar::STATE_FAILED; $class = 'tl_error'; break; default: $state = ProgressBar::STATE_IN_PROGRESS; $class = ''; } $data = [ 'state' => $state, 'currentProgress' => $record->importProgressCurrent, // field name depends on your dca 'totalCount' => $record->importProgressTotal, // field name depends on your dca 'skippedCount' => $record->importProgressSkipped, // field name depends on your dca ]; // add messages if some are available if ($record->importProgressResult) { $data['messages'] = [[ 'class' => $class, 'text' => str_replace("\n", '<br>', $record->importProgressResult), ]]; } } }