ModifyPluginViewEvent 

\FGTCLB\AcademicBase\Event\ModifyPluginViewEvent 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 getPluginName() getActionName() Dispatched
Course List ProgramList list after ModifyProgramListEvent and the seven variables of the list
Course Finder ProgramFinder finder after ModifyProgramListEvent and the seven variables of the finder
Course Data ProgramDetails show after the variables of the details

getControllerExtensionName() returns AcademicPrograms 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 , filterTypes , visitorSelection and the settings
Course Finder data , record , categories , filterTypes , listUri , preselection , programCategories (JSON) and the settings
Course Data data , record , program (the \FGTCLB\AcademicPrograms\Domain\Model\Program of the page the element sits on, or null ), facts and the settings

getSettings() of the context returns the settings of the content element merged over plugin.tx_academicprograms.settings , 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.tx_academicprograms.page.listPid , which the header of the program page links to. The listener hands it to the view of the element:

EXT:my_extension/Classes/EventListener/AddProgramListPageToProgramDetails.php
<?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);
    }
}
Copied!

An override of Details/Show.html renders the link while {programListPid} is not 0. The setting is a site setting of the set fgtclb/academic-programs. A site on the static templates sets it in its settings.yaml 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 programs are 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 programCategories to 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.

Introduced in