Skip to content

Commit

Permalink
Fix shortcut action
Browse files Browse the repository at this point in the history
  • Loading branch information
okmiim committed Dec 11, 2023
1 parent 0f440e9 commit 1d89410
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 42 deletions.
40 changes: 9 additions & 31 deletions Classes/Controller/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use HDNET\Calendarize\Domain\Model\Event;
use HDNET\Calendarize\Domain\Model\Index;
use HDNET\Calendarize\Domain\Repository\AbstractRepository;
use HDNET\Calendarize\Event\DetermineSearchEvent;
use HDNET\Calendarize\Event\PaginationEvent;
use HDNET\Calendarize\Register;
Expand All @@ -17,12 +16,10 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Utility\ClassNamingUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
Expand Down Expand Up @@ -249,42 +246,23 @@ public function listAction(
*/
public function shortcutAction(): ResponseInterface
{
$this->addCacheTags(['calendarize_shortcut']);

list($table, $uid) = explode(':', $this->getTypoScriptFrontendController()->currentRecord);
$register = Register::getRegister();

$event = null;
foreach ($register as $value) {
if ($value['tableName'] === $table) {
$repositoryName = ClassNamingUtility::translateModelNameToRepositoryName($value['modelName']);
if (class_exists($repositoryName)) {
/** @var AbstractRepository $repository */
$repository = GeneralUtility::makeInstance($repositoryName);
$event = $repository->findByUid($uid);

$this->addCacheTags(
['calendarize_' . lcfirst($value['uniqueRegisterKey']) . '_' . $event->getUid()]
);
break;
}
}
}
[$table, $uid] = explode(':', $this->getTypoScriptFrontendController()->currentRecord);
$uid = (int)$uid;

if (!($event instanceof DomainObjectInterface)) {
return $this->htmlResponse('Invalid object');
}
$configurationByTable = array_column(Register::getRegister(), null, 'tableName');
$this->addCacheTags([
'calendarize_shortcut',
'calendarize_' . lcfirst($configurationByTable[$table]['uniqueRegisterKey'] ?? 'unknown') . '_' . $uid,
]);

$limitEvents = (int)($this->settings['shortcutLimitEvents'] ?? 1);

$fetchEvent = $this->indexRepository->findByEventTraversing($event, true, false, $limitEvents);
$fetchEvent = $this->indexRepository->findByTableAndUid($table, $uid, true, false, $limitEvents)->toArray();
if (\count($fetchEvent) <= 0) {
$fetchEvent = $this->indexRepository
->findByEventTraversing($event, false, true, $limitEvents, QueryInterface::ORDER_DESCENDING);
$fetchEvent = $this->indexRepository->findByTableAndUid($table, $uid, false, true, $limitEvents, QueryInterface::ORDER_DESCENDING)->toArray();
}

$this->view->assignMultiple([
'pagination' => $this->getPagination($fetchEvent),
'indices' => $fetchEvent,
]);

Expand Down
14 changes: 3 additions & 11 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,13 @@ plugin {

# Rendering of calendarize, displayed by "Insert Record" content element
tt_content.shortcut.20.tables := addToList(tx_calendarize_domain_model_event)
tt_content.shortcut.20.conf.tx_calendarize_domain_model_event = USER
tt_content.shortcut.20.conf.tx_calendarize_domain_model_event = EXTBASEPLUGIN
tt_content.shortcut.20.conf.tx_calendarize_domain_model_event {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = Calendarize
pluginName = Calendar
vendorName = HDNET
switchableControllerActions {
Calendar {
1 = shortcut
}
}
pluginName = Shortcut

settings =< plugin.tx_calendarize.settings
settings {
insertRecord = 1
hidePagination = 1
detailPid = {$plugin.tx_calendarize.settings.defaultDetailPid}
}
Expand All @@ -142,7 +134,7 @@ tt_content.shortcut.20.conf.tx_calendarize_domain_model_event {
tt_content.shortcut.variables.shortcuts.tables := addToList(tx_calendarize_domain_model_event)
tt_content.shortcut.variables.shortcuts.conf.tx_calendarize_domain_model_event =< tt_content.shortcut.20.conf.tx_calendarize_domain_model_event

# Add you own tables with (See: EXT:calendarize/Configuration/TCA/Overrides/tt_content.php)
# Add you own tables
# tt_content.shortcut.20.tables := addToList(tx_XXXXXX_domain_model_event)
# tt_content.shortcut.20.conf.tx_XXXXX_domain_model_event =< tt_content.shortcut.20.conf.tx_calendarize_domain_model_event
# tt_content.shortcut.variables.shortcuts.tables := addToList(tx_XXXXX_domain_model_event)
Expand Down
7 changes: 7 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@
$calendar => 'past',
]
);
ExtensionUtility::configurePlugin(
'calendarize',
'Shortcut',
[
$calendar => 'shortcut',
]
);

ExtensionUtility::configurePlugin(
'calendarize',
Expand Down

0 comments on commit 1d89410

Please sign in to comment.