Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save a-r-m-i-n/bd83a1d5701003dbf01fb9670a996488 to your computer and use it in GitHub Desktop.

Select an option

Save a-r-m-i-n/bd83a1d5701003dbf01fb9670a996488 to your computer and use it in GitHub Desktop.
Set the "edit_record" action in TYPO3's LiveSearch in Backend to default action
<?php
namespace Vendor\Project\EventListeners;
use TYPO3\CMS\Backend\Search\Event\ModifyResultItemInLiveSearchEvent;
use TYPO3\CMS\Backend\Search\LiveSearch\ResultItemAction;
use TYPO3\CMS\Core\Attribute\AsEventListener;
#[AsEventListener(identifier: 'ext-project/edit-record-as-default-in-live-search-event-listener')]
class EditRecordAsDefaultActionInLiveSearchEventListener
{
public function __invoke(ModifyResultItemInLiveSearchEvent $event): void
{
$resultItem = $event->getResultItem();
$array = $resultItem->jsonSerialize();
/** @var ResultItemAction[] $actions */
$actions = $array['actions'] ?? [];
foreach ($actions as $index => $action) {
if ('edit_record' === $action->jsonSerialize()['identifier']) {
array_splice($actions, $index, 1);
array_unshift($actions, $action);
$resultItem->setActions(...$actions);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment