a2g_travel_blog/Classes/Utility/CanonicalUtility.php

66 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2023-12-04 16:40:27 +01:00
<?php
declare(strict_types=1);
namespace A2G\A2gProducts\Utility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
/**
* Description of Canonical
*
* @author Raphael Martin raphael@web-crossing.com
*/
class CanonicalUtility {
/**
* objectManager
*
* @var \TYPO3\CMS\Extbase\Object\ObjectManager
* @Extbase\Inject
*/
protected $objectManager = null;
/**
* plugin
*
* @var string
*/
static private $plugin = 'tx_a2gproducts_a2gproductsdetail';
/**
* uidParamName
*
* @var string
*/
static private $uidParamName = 'resource';
/**
* setCanonical
*
* @param type $href
*/
public function setCanonical(&$href) {
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$main = GeneralUtility::_GET(self::$plugin);
if ($main[self::$uidParamName]) {
$uriBuilder = $this->objectManager->get(UriBuilder::class);
$uriBuilder->setCreateAbsoluteUri(true);
$uriBuilder->setArguments([self::$plugin => [self::$uidParamName => $main[self::$uidParamName]]]);
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
if (isset($settings['plugin.'][self::$plugin.'.']['settings.']['canonical']) && $settings['plugin.'][self::$plugin.'.']['settings.']['canonical'] !== 0) {
$uriBuilder->setTargetPageUid($settings['plugin.'][self::$plugin.'.']['settings.']['canonical']);
$href = $uriBuilder->build();
}
}
}
}