Feature: The query events say which plugin is asking
Description
\FGTCLB\ and
\FGTCLB\, see
Feature: Narrow the profiles and contracts a plugin shows, carry the plugin they narrow
the query for now. In version 2.4 a listener could not tell the plugins apart
and narrowed every one of them alike.
get returns the plugin name, the settings
of the content element, the request, the site and its language, and the content
object of the element. A listener can therefore act for one plugin only, or read
a setting an editor made. The plugin names are the ones the plugins are
registered with,
List
,
List,
Card
,
Selected,
Selected and
Detail
, not the
content element types:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use FGTCLB\AcademicPersons\Event\ModifyProfileQueryEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
final class ShowOnlyConsentingProfiles
{
#[AsEventListener(identifier: 'my-extension/show-only-consenting-profiles')]
public function __invoke(ModifyProfileQueryEvent $event): void
{
// Both of these render a profile list, and they are two plugins.
if (!in_array($event->getPluginControllerActionContext()?->getPluginName(), ['List', 'ListAndDetail'], true)) {
return;
}
$query = $event->getQuery();
$event->addConstraint($query->equals('publicDisplayConsent', true));
}
}
The context is
null
where a query has no plugin behind it.
Impact
A listener written for version 2.4 keeps working and keeps narrowing every plugin. One that is meant for some plugins only can check the context now.