‪TYPO3CMS  10.4
SiteProcessor.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 
26 
40 {
41 
49  public function ‪process(‪ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array
50  {
51  $targetVariableName = $cObj->‪stdWrapValue('as', $processorConfiguration, 'site');
52  $processedData[$targetVariableName] = $this->‪getCurrentSite();
53  return $processedData;
54  }
55 
61  protected function ‪getCurrentSite(): ?‪SiteInterface
62  {
63  try {
64  return $this->‪getSiteFinder()->‪getSiteByPageId($this->‪getCurrentPageId());
65  } catch (‪SiteNotFoundException $e) {
66  // Do nothing
67  }
68 
69  return null;
70  }
71 
75  protected function ‪getSiteFinder(): ‪SiteFinder
76  {
77  return GeneralUtility::makeInstance(SiteFinder::class);
78  }
79 
83  protected function ‪getCurrentPageId(): int
84  {
85  return (int)‪$GLOBALS['TSFE']->id;
86  }
87 }
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:26
‪TYPO3\CMS\Frontend\DataProcessing\SiteProcessor
Definition: SiteProcessor.php:40
‪TYPO3\CMS\Core\Site\SiteFinder\getSiteByPageId
‪Site getSiteByPageId(int $pageId, array $rootLine=null, string $mountPointParameter=null)
Definition: SiteFinder.php:111
‪TYPO3\CMS\Frontend\DataProcessing\SiteProcessor\getCurrentPageId
‪int getCurrentPageId()
Definition: SiteProcessor.php:83
‪TYPO3\CMS\Core\Exception\SiteNotFoundException
Definition: SiteNotFoundException.php:26
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Frontend\DataProcessing
Definition: CommaSeparatedValueProcessor.php:16
‪TYPO3\CMS\Frontend\DataProcessing\SiteProcessor\getSiteFinder
‪SiteFinder getSiteFinder()
Definition: SiteProcessor.php:75
‪TYPO3\CMS\Frontend\DataProcessing\SiteProcessor\getCurrentSite
‪SiteInterface null getCurrentSite()
Definition: SiteProcessor.php:61
‪TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface
Definition: DataProcessorInterface.php:23
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1685
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Frontend\DataProcessing\SiteProcessor\process
‪array process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
Definition: SiteProcessor.php:49