‪TYPO3CMS  10.4
DataHandlerSlugUpdateHook.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
29 {
33  protected ‪$slugService;
34 
41  protected ‪$persistedSlugValues;
42 
47  {
48  $this->slugService = ‪$slugService;
49  }
50 
59  public function ‪processDatamap_preProcessFieldArray(array $incomingFieldArray, string $table, $id, ‪DataHandler $dataHandler): void
60  {
61  if (
62  $table !== 'pages'
63  || empty($incomingFieldArray['slug'])
64  || $this->‪isNestedHookInvocation($dataHandler)
66  || !$dataHandler->‪checkRecordUpdateAccess($table, $id, $incomingFieldArray)
67  ) {
68  return;
69  }
70 
71  $record = ‪BackendUtility::getRecordWSOL($table, (int)$id, 'slug');
72  $this->persistedSlugValues[(int)$id] = $record['slug'];
73  }
74 
87  public function ‪processDatamap_postProcessFieldArray(string $status, string $table, $id, array $fieldArray, ‪DataHandler $dataHandler): void
88  {
89  $persistedSlugValue = $this->persistedSlugValues[(int)$id] ?? null;
90 
91  if (
92  $table !== 'pages'
93  || $status !== 'update'
94  || empty($fieldArray['slug'])
95  || $persistedSlugValue === null
96  || $persistedSlugValue === $fieldArray['slug']
97  || $this->‪isNestedHookInvocation($dataHandler)
98  ) {
99  return;
100  }
101 
102  $this->slugService->rebuildSlugsForSlugChange($id, $persistedSlugValue, $fieldArray['slug'], $dataHandler->‪getCorrelationId());
103  }
104 
112  protected function ‪isNestedHookInvocation(‪DataHandler $dataHandler): bool
113  {
114  $correlationId = $dataHandler->‪getCorrelationId();
115  $correlationIdAspects = $correlationId ? $correlationId->‪getAspects() ?? [] : [];
116  return in_array(‪SlugService::CORRELATION_ID_IDENTIFIER, $correlationIdAspects, true);
117  }
118 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Redirects\Service\SlugService\CORRELATION_ID_IDENTIFIER
‪const CORRELATION_ID_IDENTIFIER
Definition: SlugService.php:54
‪TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger
‪static bool canBeInterpretedAsInteger($var)
Definition: MathUtility.php:74
‪TYPO3\CMS\Redirects\Hooks
Definition: BackendControllerHook.php:18
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook
Definition: DataHandlerSlugUpdateHook.php:29
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook\$persistedSlugValues
‪string[] $persistedSlugValues
Definition: DataHandlerSlugUpdateHook.php:39
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook\processDatamap_postProcessFieldArray
‪processDatamap_postProcessFieldArray(string $status, string $table, $id, array $fieldArray, DataHandler $dataHandler)
Definition: DataHandlerSlugUpdateHook.php:85
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook\processDatamap_preProcessFieldArray
‪processDatamap_preProcessFieldArray(array $incomingFieldArray, string $table, $id, DataHandler $dataHandler)
Definition: DataHandlerSlugUpdateHook.php:57
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook\$slugService
‪SlugService $slugService
Definition: DataHandlerSlugUpdateHook.php:32
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook\isNestedHookInvocation
‪bool isNestedHookInvocation(DataHandler $dataHandler)
Definition: DataHandlerSlugUpdateHook.php:110
‪TYPO3\CMS\Core\DataHandling\DataHandler\checkRecordUpdateAccess
‪bool checkRecordUpdateAccess($table, $id, $data=false, $hookObjectsArr=null)
Definition: DataHandler.php:6525
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:139
‪TYPO3\CMS\Core\DataHandling\DataHandler\getCorrelationId
‪CorrelationId null getCorrelationId()
Definition: DataHandler.php:9250
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Redirects\Service\SlugService
Definition: SlugService.php:48
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\getAspects
‪string[] getAspects()
Definition: CorrelationId.php:152
‪TYPO3\CMS\Redirects\Hooks\DataHandlerSlugUpdateHook\__construct
‪__construct(SlugService $slugService)
Definition: DataHandlerSlugUpdateHook.php:44