added event to extend detail pages (#3209)

This commit is contained in:
Kevin Papst
2022-03-19 23:54:40 +01:00
committed by GitHub
parent a8ac6b2eda
commit 4b069edd33
12 changed files with 225 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ use App\Entity\ActivityRate;
use App\Entity\MetaTableTypeInterface;
use App\Entity\Project;
use App\Entity\Team;
use App\Event\ActivityDetailControllerEvent;
use App\Event\ActivityMetaDefinitionEvent;
use App\Event\ActivityMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
@@ -140,6 +141,11 @@ final class ActivityController extends AbstractController
$teams = $activity->getTeams();
}
// additional boxes by plugins
$event = new ActivityDetailControllerEvent($activity);
$this->dispatcher->dispatch($event);
$boxes = $event->getController();
return $this->render('activity/details.html.twig', [
'activity' => $activity,
'stats' => $stats,
@@ -147,6 +153,7 @@ final class ActivityController extends AbstractController
'team' => $defaultTeam,
'teams' => $teams,
'now' => $now,
'boxes' => $boxes
]);
}

View File

@@ -16,6 +16,7 @@ use App\Entity\CustomerComment;
use App\Entity\CustomerRate;
use App\Entity\MetaTableTypeInterface;
use App\Entity\Team;
use App\Event\CustomerDetailControllerEvent;
use App\Event\CustomerMetaDefinitionEvent;
use App\Event\CustomerMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
@@ -300,7 +301,6 @@ final class CustomerController extends AbstractController
$attachments = [];
$comments = null;
$teams = null;
$projects = null;
$rates = [];
$now = $this->getDateTimeFactory()->createDateTime();
@@ -331,6 +331,11 @@ final class CustomerController extends AbstractController
$teams = $customer->getTeams();
}
// additional boxes by plugins
$event = new CustomerDetailControllerEvent($customer);
$this->dispatcher->dispatch($event);
$boxes = $event->getController();
return $this->render('customer/details.html.twig', [
'customer' => $customer,
'comments' => $comments,
@@ -342,6 +347,7 @@ final class CustomerController extends AbstractController
'customer_now' => new \DateTime('now', $timezone),
'rates' => $rates,
'now' => $now,
'boxes' => $boxes
]);
}

View File

@@ -17,6 +17,7 @@ use App\Entity\ProjectComment;
use App\Entity\ProjectRate;
use App\Entity\Rate;
use App\Entity\Team;
use App\Event\ProjectDetailControllerEvent;
use App\Event\ProjectMetaDefinitionEvent;
use App\Event\ProjectMetaDisplayEvent;
use App\Export\Spreadsheet\EntityWithMetaFieldsExporter;
@@ -348,6 +349,11 @@ final class ProjectController extends AbstractController
$teams = $project->getTeams();
}
// additional boxes by plugins
$event = new ProjectDetailControllerEvent($project);
$this->dispatcher->dispatch($event);
$boxes = $event->getController();
return $this->render('project/details.html.twig', [
'project' => $project,
'comments' => $comments,
@@ -358,6 +364,7 @@ final class ProjectController extends AbstractController
'teams' => $teams,
'rates' => $rates,
'now' => $now,
'boxes' => $boxes
]);
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Event;
/**
* Triggered for activity detail pages, to add additional content boxes.
*
* @see https://symfony.com/doc/5.4/templates.html#embedding-controllers
*/
final class ActivityDetailControllerEvent extends AbstractActivityEvent
{
private $controller = [];
public function addController(string $controller): void
{
$this->controller[] = $controller;
}
public function getController(): array
{
return $this->controller;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Event;
/**
* Triggered for customer detail pages, to add additional content boxes.
*
* @see https://symfony.com/doc/5.4/templates.html#embedding-controllers
*/
final class CustomerDetailControllerEvent extends AbstractCustomerEvent
{
private $controller = [];
public function addController(string $controller): void
{
$this->controller[] = $controller;
}
public function getController(): array
{
return $this->controller;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Event;
/**
* Triggered for project detail pages, to add additional content boxes.
*
* @see https://symfony.com/doc/5.4/templates.html#embedding-controllers
*/
final class ProjectDetailControllerEvent extends AbstractProjectEvent
{
private $controller = [];
public function addController(string $controller): void
{
$this->controller[] = $controller;
}
public function getController(): array
{
return $this->controller;
}
}