ModifyPluginViewEvent
\FGTCLB\ belongs to
academic_base, and the plugins of seven academic extensions
dispatch it. It hands a listener the view of a plugin right before it
renders, so the listener can assign further variables that a template override
renders. The event, its methods and the context it carries are described in
the documentation of academic_base.
This page states what the plugins of academic_programs pass in.
When it is dispatched
Each of the three content elements dispatches the event once per rendering, after its action assigned its own variables:
| Content element |
get |
get |
Dispatched |
|---|---|---|---|
| Course List | Program | list | after ModifyProgramListEvent and the seven variables of the list |
| Course Finder | Program | finder | after ModifyProgramListEvent and the seven variables of the finder |
| Course Data | Program | show | after the variables of the details |
get returns Academic for all three.
A submission of the filter form of the list is answered with a redirect and
renders nothing, so it dispatches no event. The program page is no plugin and
dispatches ModifyProgramDataEvent instead.
What this extension passes in
The view holds these variables when the event fires. A listener that assigns one of them again replaces it in the templates.
| Content element | Variables |
|---|---|
| Course List |
programs
,
data
(the content element record as an
array),
record
,
demand
,
categories
,
filter,
visitor and the
settings
|
| Course Finder |
data
,
record
,
categories
,
filter,
list,
preselection
,
program (JSON) and the
settings
|
| Course Data |
data
,
record
,
program
(the
\FGTCLB\ of the page the
element sits on, or
null
),
facts
and the
settings
|
get of the context returns the settings of the content
element merged over
plugin., the
values of the site settings included.
Example
A site places the Course Data element on its program pages and
wants a link below the facts that leads back to the program list. The site
already names that page in the site setting
plugin., which the header of the
program page links to. The listener hands it to the view of the element:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use FGTCLB\AcademicBase\Event\ModifyPluginViewEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
final class AddProgramListPageToProgramDetails
{
#[AsEventListener(identifier: 'my-extension/add-program-list-page-to-program-details')]
public function __invoke(ModifyPluginViewEvent $event): void
{
$context = $event->getPluginControllerActionContext();
if ($context->getControllerExtensionName() !== 'AcademicPrograms'
|| $context->getPluginName() !== 'ProgramDetails'
) {
return;
}
$listPid = (int)($context->getSite()?->getSettings()->get('plugin.tx_academicprograms.page.listPid', 0) ?? 0);
$event->getView()->assign('programListPid', $listPid);
}
}
An override of Details/ renders the link while
{program is not 0. The setting is a site setting of the set
fgtclb/. A site on the static templates sets it in its
settings. as well, or the listener reads 0 there.
Rules and pitfalls
- The event fires for the plugins of seven academic extensions. Check the extension name and the plugin name before acting, as the example does.
- A variable the action assigned is replaced only in the view. The query has
run already: programs a listener assigns as
programsare rendered, but the filter keeps offering the categories of the queried programs. A change of which programs are shown belongs in ModifyProgramDemandEvent or ModifyProgramListEvent. - The finder hands
programto the browser as JSON. A listener that replaces it has to keep its shape, a list with one list of category uids per program, or the narrowing of the options stops.Categories
Introduced in
- Feature: The plugins dispatch the plugin view event made the three content elements dispatch the event in 3.0.
- Breaking: The program controllers are final names the event as the replacement of a
subclass of
Detailsthat added a view variable.Controller - The event itself was introduced by academic_base 3.0.