Just like the other theme components, this one requires some route aliases to work. Please refer to the configurations overview to learn about the route alias details.
- all_task
- task
In order to use this component, your task class has to implement the KevinPapst\AdminLTEBundle\Model\TaskInterface
<?php
namespace App\Model;
use KevinPapst\AdminLTEBundle\Model\TaskInterface;
class TaskModel implements TaskInterface
{
// implement interface methods
}
The bundle provides the TaskModel
as a ready to use implementation of the TaskInterface
.
In case you activated service discovery and auto-wiring in your app, you can write an EventSubscriber which will be automatically registered in your container:
<?php
// src/EventSubscriber/TaskSubscriber.php
namespace App\EventSubscriber;
use KevinPapst\AdminLTEBundle\Event\TaskListEvent;
use KevinPapst\AdminLTEBundle\Helper\Constants;
use KevinPapst\AdminLTEBundle\Model\TaskModel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class TaskSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
TaskListEvent::class => ['onTasks', 100],
];
}
public function onTasks(TaskListEvent $event)
{
$task = new TaskModel();
$task
->setId(1)
->setTitle('My task')
->setColor(Constants::COLOR_AQUA)
->setProgress(80)
;
$event->addTask($task);
/*
* You can also set the total number of tasks which could be different from those displayed in the navbar
* If no total is set, the total will be calculated on the number of tasks added to the event
*/
$event->setTotal(15);
}
}
If your application is using the classical approach of manually registering Services and EventListener use this method.
Write an EventListener to work with the TaskListEvent
:
<?php
// src/EventListener/TaskListListener.php
namespace App\EventListener;
use KevinPapst\AdminLTEBundle\Event\TaskListEvent;
use KevinPapst\AdminLTEBundle\Model\TaskModel;
class TaskListListener
{
public function onListTasks(TaskListEvent $event)
{
foreach($this->getTasks() as $task) {
$event->addTask($task);
}
}
protected function getTasks()
{
// see above in TaskSubscriber for a full example
return [new TaskModel()];
}
}
Finally, you need to attach your new listener to the event system:
services:
app.task_list_listener:
class: App\EventListener\TaskListListener
tags:
- { name: kernel.event_listener, event: theme.tasks, method: onListTasks }
Please go back to the AdminLTE bundle documentation to find out more about using the theme.