From b06aa109d5b47427db39480812f354dc66768aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Thu, 10 Oct 2019 14:19:42 +0200 Subject: [PATCH] Implement default image for og:image meta tag --- .../MetaTag/OpenGraphMetaTagManager.php | 45 +++++++++++++++++++ .../TypoScript/constants.typoscript | 2 + .../Configuration/TypoScript/setup.typoscript | 1 + .../typo3conf/ext/ep_theme/ext_localconf.php | 6 +++ 4 files changed, 54 insertions(+) create mode 100644 public/typo3conf/ext/ep_theme/Classes/MetaTag/OpenGraphMetaTagManager.php diff --git a/public/typo3conf/ext/ep_theme/Classes/MetaTag/OpenGraphMetaTagManager.php b/public/typo3conf/ext/ep_theme/Classes/MetaTag/OpenGraphMetaTagManager.php new file mode 100644 index 00000000..3ae358d9 --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Classes/MetaTag/OpenGraphMetaTagManager.php @@ -0,0 +1,45 @@ +properties)) { + /** @var ConfigurationManager $configurationManager */ + $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); + $settings = GeneralUtility::removeDotsFromTS( + $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT) + ); + $imageSource = $settings['plugin']['tx_eptheme']['settings']['ogDefaultImage']; + $resourceFactory = ResourceFactory::getInstance(); + $image = $resourceFactory->getFileObjectFromCombinedIdentifier(sprintf('1:%s', $imageSource)); + + if (null !== $image) { + /** @var ImageService $imageService */ + $imageService = GeneralUtility::makeInstance(ImageService::class); + $processedImage = $imageService->applyProcessingInstructions($image, ['width' => '1200']); + + $this->addProperty( + 'og:image', + $imageService->getImageUri($processedImage, true), + [ + 'url' => $imageService->getImageUri($processedImage, true), + 'width' => $processedImage->getProperty('width'), + 'height' => $processedImage->getProperty('height'), + 'type' => $processedImage->getMimeType(), + ] + ); + } + } + + return parent::renderAllProperties(); + } +} \ No newline at end of file diff --git a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript index 114b9ba5..c4463a82 100644 --- a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript +++ b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/constants.typoscript @@ -90,6 +90,8 @@ plugin.tx_eptheme { facebookViewContentProductUid = # cat=eptheme/100/150; type=string; label=Facebook ViewContent 'name internal' facebookViewContentNameInternal = + # cat=eptheme/100/160; type=string; label=OG default image + ogDefaultImage = user_upload/Open_Graph__Linkvorschau_/Home-Vorschaubild.jpg # cat=eptheme; type=string; label=Slider storage PID sliderStoragePid = diff --git a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript index 5d7df14c..7b3c7fe1 100644 --- a/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript +++ b/public/typo3conf/ext/ep_theme/Configuration/TypoScript/setup.typoscript @@ -94,6 +94,7 @@ plugin.tx_eptheme { productUid = {$plugin.tx_eptheme.settings.facebookViewContentProductUid} nameInternal = {$plugin.tx_eptheme.settings.facebookViewContentNameInternal} } + ogDefaultImage = {$plugin.tx_eptheme.settings.ogDefaultImage} domainsToTrack = bpn.ep-reisen.de,www.ski-boarderweek.de,www.ski-wochenenden.de,www.snowzone.net,www.unichamp.de } view { diff --git a/public/typo3conf/ext/ep_theme/ext_localconf.php b/public/typo3conf/ext/ep_theme/ext_localconf.php index b50e4f81..d3cd8edb 100644 --- a/public/typo3conf/ext/ep_theme/ext_localconf.php +++ b/public/typo3conf/ext/ep_theme/ext_localconf.php @@ -14,6 +14,12 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] = 'tx_eptheme_slides'; $GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['default'] = 'EXT:ep_theme/Configuration/RTE/Default.yaml'; $GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['ep-reisen'] = 'EXT:ep_theme/Configuration/RTE/Default.yaml'; +$metaTagManagerRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry::class); +$metaTagManagerRegistry->registerManager( + 'ep_opengraph', + \EP\EpTheme\MetaTag\OpenGraphMetaTagManager::class +); + \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( 'EP.EpTheme', 'SimpleForm',