ModifyPluginViewEvent
\FGTCLB\ belongs to
academic_base, and the plugins of seven academic extensions
dispatch it. It hands a listener the view of a plugin once the plugin has
assigned its own variables, so a listener adds a variable to the templates
without replacing the controller. The event itself, and the rules that apply to
every plugin, are described on its page in the manual of academic_base.
This page describes what the content elements of academic_partners
pass in.
When it is dispatched
All four content elements dispatch it once each time they render, as the last step of their action:
| Content element | Plugin name | Action | Dispatched after |
|---|---|---|---|
| Partner List |
List
|
list
| ModifyPartnerListEvent and the pagination |
| Partner Map |
Map
|
map
| ModifyPartnerListEvent |
| Partners Linked |
Partnerships |
partnerships | reading the partnerships of the page |
| Partner Logo Teaser |
Partnerships |
partnerships | reading the partnerships of the page |
What this extension passes in
| Method | Returns |
|---|---|
get | The context of the content element: the extension name
Academic, the plugin and action name of the table
above, the request, the site and its language, the content object
and the settings of the content element, its FlexForm merged over
plugin.. |
get | The view, with the variables the action assigned. |
The variables a listener finds in the view:
| Content element | Variables |
|---|---|
| Partner List |
{partners}
,
{categories}
,
{demand}
,
{filter,
{visitor,
{data}
,
{record}
, and with the pagination enabled
{paginator}
,
{pagination}
and
{demand |
| Partner Map | the same, without the pagination |
| Partners Linked, Partner Logo Teaser |
{partnerships}
,
{partnership,
{partnerships,
{data}
,
{record}
|
Example
A site shows a link to its page of all partners below the logo teaser of a project page. The uid of that page is a site setting of the site package, and a listener hands it to the template of the teaser:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use FGTCLB\AcademicBase\Event\ModifyPluginViewEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
final class AddAllPartnersPageToTheTeaser
{
#[AsEventListener(identifier: 'my-extension/add-all-partners-page-to-the-teaser')]
public function __invoke(ModifyPluginViewEvent $event): void
{
$context = $event->getPluginControllerActionContext();
if ($context->getControllerExtensionName() !== 'AcademicPartners'
|| $context->getPluginName() !== 'PartnershipsTeaser'
) {
return;
}
$pageUid = (int)($context->getSite()?->getSettings()->get('myExtension.allPartnersPage') ?? 0);
if ($pageUid > 0) {
$event->getView()->assign('allPartnersPage', $pageUid);
}
}
}
An override of Templates/ renders the
link with
<f:.
Rules and pitfalls
Check the extension name and the plugin name. One listener receives the
event of every academic plugin that dispatches it.
List
is the plugin name of the partner
list and of plugins of other academic extensions, so the extension name tells
them apart.
A replaced variable is replaced in the view only. A listener that assigns
{partners}
again changes what the template renders, not the pagination,
which was built from the partners before, nor the categories of the filter. A
change of which partners are shown belongs in
ModifyPartnerListEvent.
The partnership content elements are cached. Partners Linked and Partner Logo Teaser are rendered when the page is rendered, and the page is cached with what the listener assigned, so a listener cannot assign something different for different visitors there. The partner list and the map are not cached, a listener runs on every request that renders them.
Introduced in
- Feature: The plugins dispatch the plugin view event made the four content elements dispatch the event.