diff --git a/CHANGELOG.md b/CHANGELOG.md index e5ff3c4f..af623d42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file. We will follow [Semantic Versioning](http://semver.org/). ## UNRELEASED +### Added +- `TypoScriptStructuredDataProvider` to add structured data to the page, configured with TypoScript (premium functionality) + ### Fixed - Renamed `JavascriptModules.php` to `JavaScriptModules.php` diff --git a/Classes/StructuredData/TypoScriptStructuredDataProvider.php b/Classes/StructuredData/TypoScriptStructuredDataProvider.php new file mode 100644 index 00000000..7dc13a8b --- /dev/null +++ b/Classes/StructuredData/TypoScriptStructuredDataProvider.php @@ -0,0 +1,54 @@ +> + */ + public function getData(): array + { + $data = []; + + foreach ( + $this->getTyposcriptFrontendController()->config['config']['structuredData.']['data.'] ?? [] as $dataConfig + ) { + if (array_key_exists('type', $dataConfig) && array_key_exists('context', $dataConfig)) { + $item = []; + $config = $this->typoScriptService->convertTypoScriptArrayToPlainArray($dataConfig); + + foreach ($config as $key => $value) { + $cObject = $key . '.'; + if (isset($dataConfig[$cObject])) { + $value = $this->getTyposcriptFrontendController()->cObj->stdWrap($key, $dataConfig[$cObject]); + } + $key = in_array($key, ['type', 'context']) ? '@' . $key : $key; + + $item[$key] = $value; + } + $data[] = $item; + } + } + + return (array)$data; + } + + protected function getTyposcriptFrontendController(): TypoScriptFrontendController + { + return $GLOBALS['TSFE']; + } +} diff --git a/Configuration/TypoScript/Setup/Config.typoscript b/Configuration/TypoScript/Setup/Config.typoscript index 6be0fc2f..f52d2f51 100644 --- a/Configuration/TypoScript/Setup/Config.typoscript +++ b/Configuration/TypoScript/Setup/Config.typoscript @@ -10,6 +10,11 @@ config { site { provider = YoastSeoForTypo3\YoastSeo\StructuredData\SiteStructuredDataProvider } + + typoscript { + provider = YoastSeoForTypo3\YoastSeo\StructuredData\TypoScriptStructuredDataProvider + after = breadcrumb + } } pageTitleProviders { yoastRecord {