Skip to content

Commit

Permalink
Merge branch 'feature/67976-redirects' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tinzog committed Nov 25, 2024
2 parents 5382e34 + 1e41968 commit c9fadc8
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,10 @@ public function findByPropertyWithJoin(
$splitRow['mmtbl']['uid_local'],
$splitRow['mmtbl']['uid_foreign'],
];
if(isset($splitRow['mmtbl']['tablenames']))
{
if (isset($splitRow['mmtbl']['tablenames'])) {
$mmIdentityProperties[] = $splitRow['mmtbl']['tablenames'];
}
if(isset($splitRow['mmtbl']['fieldname']))
{
if (isset($splitRow['mmtbl']['fieldname'])) {
$mmIdentityProperties[] = $splitRow['mmtbl']['fieldname'];
}
$splitRows[hash('sha1', json_encode($mmIdentityProperties, JSON_THROW_ON_ERROR))] = $splitRow;
Expand Down
12 changes: 12 additions & 0 deletions Classes/Controller/Traits/ControllerModuleTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

use In2code\In2publishCore\Backend\Button\ModuleShortcutButton;
use In2code\In2publishCore\CommonInjection\ModuleTemplateFactoryInjection;
use In2code\In2publishCore\Event\ModuleTemplateWasPreparedForRendering;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
Expand All @@ -43,6 +45,8 @@

/**
* @property Request $request
* @property EventDispatcherInterface $eventDispatcher
* @property string $actionMethodName
*/
trait ControllerModuleTemplate
{
Expand Down Expand Up @@ -84,6 +88,14 @@ protected function render(): string
$buttonBar->addButton($moduleShortcutButton);

$this->moduleTemplate->setContent($this->view->render());

$event = new ModuleTemplateWasPreparedForRendering(
$this->moduleTemplate,
static::class,
$this->actionMethodName
);
$this->eventDispatcher->dispatch($event);

return $this->moduleTemplate->renderContent();
}
}
64 changes: 64 additions & 0 deletions Classes/Event/ModuleTemplateWasPreparedForRendering.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/*
* Copyright notice
*
* (c) 2024 in2code.de and the following authors:
* Daniel Hoffmann <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/

namespace In2code\In2publishCore\Event;

use TYPO3\CMS\Backend\Template\ModuleTemplate;

final class ModuleTemplateWasPreparedForRendering
{
private ModuleTemplate $moduleTemplate;
private string $controllerClass;
private string $actionMethodName;

public function __construct(
ModuleTemplate $moduleTemplate,
string $controllerClass,
string $actionMethodName
) {
$this->moduleTemplate = $moduleTemplate;
$this->controllerClass = $controllerClass;
$this->actionMethodName = $actionMethodName;
}

public function getModuleTemplate(): ModuleTemplate
{
return $this->moduleTemplate;
}

public function getControllerClass(): string
{
return $this->controllerClass;
}

public function getActionMethodName(): string
{
return $this->actionMethodName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use In2code\In2publishCore\Features\RedirectsSupport\Domain\Dto\Filter;
use In2code\In2publishCore\Features\RedirectsSupport\Domain\Model\SysRedirectDatabaseRecord;
use In2code\In2publishCore\Features\RedirectsSupport\Domain\Repository\SysRedirectRepository;
use In2code\In2publishCore\Features\RedirectsSupport\Event\RedirectsWereFilteredForListing;
use In2code\In2publishCore\Service\ForeignSiteFinderInjection;
use Psr\Http\Message\ResponseInterface;
use Throwable;
Expand Down Expand Up @@ -154,7 +155,11 @@ public function listAction(Filter $filter = null, int $page = 1): ResponseInterf
$this->demandResolver->resolveDemand($demands, $recordCollection);

$redirects = $this->getRedirectsByStateFromFilter($recordTree, $filter);
$paginator = new ArrayPaginator($redirects, $page, 15);

$event = new RedirectsWereFilteredForListing($redirects);
$this->eventDispatcher->dispatch($event);

$paginator = new ArrayPaginator($event->getRedirects(), $page, 15);
$pagination = new SimplePagination($paginator);
$this->view->assignMultiple(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* Copyright notice
*
* (c) 2024 in2code.de and the following authors:
* Daniel Hoffmann <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/

namespace In2code\In2publishCore\Features\RedirectsSupport\Event;

final class RedirectsWereFilteredForListing
{
private array $redirects;

public function __construct(array $redirects)
{
$this->redirects = $redirects;
}

public function getRedirects(): array
{
return $this->redirects;
}

public function setRedirects(array $redirects): void
{
$this->redirects = $redirects;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace In2code\In2publishCore\Features\RedirectsSupport\ViewHelpers;

/*
* Copyright notice
*
* (c) 2024 in2code.de
* Daniel Hoffmann <[email protected]>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/

use In2code\In2publishCore\Features\RedirectsSupport\Domain\Model\SysRedirectDatabaseRecord;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;

class ShowReasonsButtonViewHelper extends AbstractTagBasedViewHelper
{
protected $tagName = 'a';

public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerArgument('redirectRecord', SysRedirectDatabaseRecord::class, '', true);
}

public function render(): string
{
/**
* @var $redirectRecord SysRedirectDatabaseRecord
*/
$redirectRecord = $this->arguments['redirectRecord'];
$this->tag->addAttribute('href', '#');
$this->tag->setContent($this->renderChildren());
$modalConfiguration = [
'settings' => [
'title' => LocalizationUtility::translate('LLL:EXT:in2publish_core/Resources/Private/Language/locallang_mod5.xlf:modal.reasons.title'),
'content' => implode("\r\n", $redirectRecord->getReasonsWhyTheRecordIsNotPublishableHumanReadable()),
'severity' => 1,
],
'buttons' => [
'abort' => [
'text' => 'Abort',
'btnClass' => 'btn btn-default',
'name' => 'abort',
'active' => true,
],
],
];
$this->tag->addAttribute('data-modal-configuration', json_encode($modalConfiguration));

return $this->tag->render();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ModuleTemplateWasPreparedForRendering

## When

This event is fired each time a backend module is opened.

## What

* `moduleTemplate`: an object of type TYPO3\CMS\Backend\Template\ModuleTemplate
* `controllerClass`: controller class calling the event
* `actionMethodName`: action method name calling the event

## Possibilities

With this event you can add e.g. buttons to the docheader of a backend module.

### Example

This example shows you how to add a button to the docheader of the redirect module.

```php
use In2code\In2publish\Features\ContentLanguageControl\Toolbar\LanguageSelectionButtonInjection;
use In2code\In2publishCore\Event\ModuleTemplateWasPreparedForRendering;
use In2code\In2publishCore\Features\RedirectsSupport\Controller\RedirectController;

class ModuleTemplateButtonBarSelectionRenderer
{
use LanguageSelectionButtonInjection;

public function whenModuleTemplateWasPreparedForRendering(ModuleTemplateWasPreparedForRendering $event): void
{
if (RedirectController::class === $event->getControllerClass() && 'listAction' === $event->getActionMethodName()){
$moduleTemplate = $event->getModuleTemplate();
$moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($this->languageSelectionButton);
}
}
}
```
44 changes: 44 additions & 0 deletions Documentation/Developers/Events/RedirectsWereFilteredForListing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# RedirectsWereFilteredForListing

## When

The event is fired after the redirects are filtered for display in the listAction of the RedirectController.

## What

* `redirects`: an array of SysRedirectDatabaseRecord

## Possibilities

With this event you can filter the records in more detail on your own.

### Example

This example show how to filter the redirects with the Language Uid of the Parent Page.

```php
class FilterRedirectsBySelectedLanguages
{
use UserSelectionServiceInjection;
use RawRecordServiceInjection;

public function __invoke(RedirectsWereFilteredForListing $event): void
{
$redirects = $event->getRedirects();
$selectedLanguages = [-1,0,4];

$redirects = array_filter($redirects, function (SysRedirectDatabaseRecord $redirect) use ($selectedLanguages) {
$pid = (int)$redirect->getLocalProps()['pid'];
if (0 === $pid) {
return true;
}
$record = $this->rawRecordService->getRawRecord('pages', $pid, 'local');
if (in_array($record['sys_language_uid'], $selectedLanguages)){
return true;
}
});

$event->setRedirects($redirects);
}
}
```
4 changes: 4 additions & 0 deletions Resources/Private/Language/de.locallang_mod5.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<source>TYPO3 Content Publisher - Redirects</source>
<target state="translated">TYPO3 Content Publisher - Redirects</target>
</trans-unit>
<trans-unit id="modal.reasons.title">
<source>Redirect is not publishable</source>
<target state="translated">Redirect kann nicht publiziert werden.</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions Resources/Private/Language/locallang_mod5.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<trans-unit id="mlang_labels_tablabel">
<source>TYPO3 Content Publisher - Redirects</source>
</trans-unit>
<trans-unit id="modal.reasons.title">
<source>Redirect is not publishable</source>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit c9fadc8

Please sign in to comment.