Skip to content
Snippets Groups Projects
Verified Commit 4cfcbae4 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Add schemald from sg_seo

parent 107d3820
No related branches found
No related tags found
1 merge request!49[TASK] Add schemald from sg_seo
<?php <?php
namespace SGalinski\SgNews\Controller;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
* *
...@@ -26,15 +23,15 @@ namespace SGalinski\SgNews\Controller; ...@@ -26,15 +23,15 @@ namespace SGalinski\SgNews\Controller;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
namespace SGalinski\SgNews\Controller;
use SGalinski\SgNews\Domain\Model\Category; use SGalinski\SgNews\Domain\Model\Category;
use SGalinski\SgNews\Domain\Model\News; use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Domain\Repository\CategoryRepository; use SGalinski\SgNews\Domain\Repository\CategoryRepository;
use SGalinski\SgNews\Domain\Repository\NewsRepository; use SGalinski\SgNews\Domain\Repository\NewsRepository;
use SGalinski\SgNews\Domain\Repository\TagRepository; use SGalinski\SgNews\Domain\Repository\TagRepository;
use SGalinski\SgNews\Domain\Service\NewsService; use SGalinski\SgNews\Domain\Service\NewsService;
use SGalinski\SgNews\Service\HeaderMetaDataService;
use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/** /**
* Controller that handles the news single view page * Controller that handles the news single view page
...@@ -82,9 +79,9 @@ class SingleViewController extends AbstractController { ...@@ -82,9 +79,9 @@ class SingleViewController extends AbstractController {
'<' '<'
)) { )) {
return NULL; return NULL;
} else {
return $this->htmlResponse();
} }
return $this->htmlResponse();
} }
/** @var Category $newsCategory */ /** @var Category $newsCategory */
...@@ -96,9 +93,9 @@ class SingleViewController extends AbstractController { ...@@ -96,9 +93,9 @@ class SingleViewController extends AbstractController {
'<' '<'
)) { )) {
return NULL; return NULL;
} else {
return $this->htmlResponse();
} }
return $this->htmlResponse();
} }
$newsMetaData = $this->newsService->getMetaDataForNews($news, $newsCategory); $newsMetaData = $this->newsService->getMetaDataForNews($news, $newsCategory);
...@@ -120,9 +117,9 @@ class SingleViewController extends AbstractController { ...@@ -120,9 +117,9 @@ class SingleViewController extends AbstractController {
); );
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) { if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL; return NULL;
} else {
return $this->htmlResponse();
} }
return $this->htmlResponse();
} }
/** /**
......
<?php <?php
namespace SGalinski\SgNews\Domain\Service;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
* *
...@@ -26,10 +23,15 @@ namespace SGalinski\SgNews\Domain\Service; ...@@ -26,10 +23,15 @@ namespace SGalinski\SgNews\Domain\Service;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
namespace SGalinski\SgNews\Domain\Service;
use SGalinski\SgNews\Domain\Model\Category; use SGalinski\SgNews\Domain\Model\Category;
use SGalinski\SgNews\Domain\Model\News; use SGalinski\SgNews\Domain\Model\News;
use TYPO3\CMS\Core\Resource\FileRepository; use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference; use TYPO3\CMS\Extbase\Domain\Model\FileReference;
...@@ -72,6 +74,23 @@ class NewsService implements SingletonInterface { ...@@ -72,6 +74,23 @@ class NewsService implements SingletonInterface {
]; ];
} }
$customSchemaJson = '';
if (ExtensionManagementUtility::isLoaded('sg_seo')) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$schemaJson = $queryBuilder->select('tx_sgseo_schemajson')
->from('pages')
->where(
$queryBuilder->expr()->eq(
'uid',
$queryBuilder->createNamedParameter($newsId, Connection::PARAM_INT)
)
)->execute()->fetchOne();
if (!empty($schemaJson)) {
$customSchemaJson = $schemaJson;
}
}
$newsRecord = array_merge( $newsRecord = array_merge(
[ [
'category' => $category, 'category' => $category,
...@@ -79,7 +98,8 @@ class NewsService implements SingletonInterface { ...@@ -79,7 +98,8 @@ class NewsService implements SingletonInterface {
], ],
$singleNewsImageData, $singleNewsImageData,
$teaserImageData, $teaserImageData,
['media' => $fileObjects] ['media' => $fileObjects],
['customSchemaJson' => $customSchemaJson]
); );
$this->cachedSingleNews[$newsId] = $newsRecord; $this->cachedSingleNews[$newsId] = $newsRecord;
......
<?php <?php
defined('TYPO3') or die();
/** /**
* *
* Copyright notice * Copyright notice
...@@ -26,6 +25,8 @@ defined('TYPO3') or die(); ...@@ -26,6 +25,8 @@ defined('TYPO3') or die();
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
*/ */
defined('TYPO3') or die();
$localLangDbPath = 'LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:'; $localLangDbPath = 'LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:';
$localLangBackendPath = 'LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:'; $localLangBackendPath = 'LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:';
foreach ( foreach (
...@@ -65,6 +66,7 @@ $GLOBALS['TCA']['pages']['types'][\SGalinski\SgNews\Utility\BackendNewsUtility:: ...@@ -65,6 +66,7 @@ $GLOBALS['TCA']['pages']['types'][\SGalinski\SgNews\Utility\BackendNewsUtility::
tx_sgnews_content_from_another_page, tx_sgnews_related_news, tx_sgnews_tags, tx_sgnews_content_from_another_page, tx_sgnews_related_news, tx_sgnews_tags,
--div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.seo, --div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.seo,
--palette--;;seo, --palette--;;seo,
' . (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sg_seo') ? 'tx_sgseo_schemajson,' : '') . '
--palette--;;robots, --palette--;;robots,
--palette--;;canonical, --palette--;;canonical,
--palette--;;sitemap, --palette--;;sitemap,
...@@ -95,6 +97,7 @@ $GLOBALS['TCA']['pages']['types'][\SGalinski\SgNews\Utility\BackendNewsUtility:: ...@@ -95,6 +97,7 @@ $GLOBALS['TCA']['pages']['types'][\SGalinski\SgNews\Utility\BackendNewsUtility::
title, slug, tx_projectbase_path_segment, tx_projectbase_excludefromsluggeneration, tx_realurl_pathsegment, tx_realurl_exclude, title, slug, tx_projectbase_path_segment, tx_projectbase_excludefromsluggeneration, tx_realurl_pathsegment, tx_realurl_exclude,
--div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.seo, --div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.seo,
--palette--;;seo, --palette--;;seo,
' . (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('sg_seo') ? 'tx_sgseo_schemajson,' : '') . '
--palette--;;robots, --palette--;;robots,
--palette--;;canonical, --palette--;;canonical,
--palette--;;sitemap, --palette--;;sitemap,
......
<f:alias map="{leftBrace: '{', rightBrace: '}'}"> <f:alias map="{leftBrace: '{', rightBrace: '}'}">
<script type="application/ld+json"> <script type="application/ld+json">
{leftBrace} {leftBrace}
"@context": "http://schema.org/", <f:if condition="{newsMetaData.customSchemaJson}">
"@type": "NewsArticle", <f:then>
"mainEntityOfPage": {leftBrace} <f:format.raw>{newsMetaData.customSchemaJson}</f:format.raw>
"@type": "WebPage", </f:then>
"@id": "<f:uri.page absolute="TRUE"/>" <f:else>
{rightBrace}, <f:render section="default" arguments="{_all}"/>
"author": "{newsMetaData.news.author}", </f:else>
"publisher": {leftBrace} </f:if>
"@type": "Organization"{f:if(condition: settings.publisher, then:',')} {rightBrace}
<f:if condition="{settings.publisher}">"name": "{settings.publisher}"{f:if(condition: settings.publisherLogo, then:',')}</f:if> </script>
<f:if condition="{settings.publisherLogo}">"logo": {leftBrace}
"@type": "ImageObject",
"url": "{settings.publisherLogo}"
{rightBrace}</f:if>
{rightBrace},
<f:if condition="{newsMetaData.imageObject}">
"image": "<f:uri.image absolute="TRUE" image="{newsMetaData.imageObject}" />",
</f:if>
"headline": "{newsMetaData.news.navTitle}",
"description": "{newsMetaData.news.description}",
"dateCreated": "<f:format.date format="Y-m-d">{newsMetaData.news.creationDate}</f:format.date>",
"datePublished": "<f:format.date format="Y-m-d">{newsMetaData.news.creationDate}</f:format.date>",
"dateModified": "<f:format.date format="Y-m-d">{newsMetaData.news.lastUpdated}</f:format.date>"
{rightBrace}
</script>
</f:alias> </f:alias>
<f:section name="default">
"@context": "http://schema.org/",
"@type": "NewsArticle",
"mainEntityOfPage": {leftBrace}
"@type": "WebPage",
"@id": "<f:uri.page absolute="TRUE"/>"
{rightBrace},
"author": "{newsMetaData.news.author}",
"publisher": {leftBrace}
"@type": "Organization"{f:if(condition: settings.publisher, then:',')}
<f:if condition="{settings.publisher}">"name": "{settings.publisher}"{f:if(condition: settings.publisherLogo, then:',')}</f:if>
<f:if condition="{settings.publisherLogo}">"logo": {leftBrace}
"@type": "ImageObject",
"url": "{settings.publisherLogo}"
{rightBrace}</f:if>
{rightBrace},
<f:if condition="{newsMetaData.imageObject}">
"image": "<f:uri.image absolute="TRUE" image="{newsMetaData.imageObject}" />",
</f:if>
"headline": "{newsMetaData.news.navTitle}",
"description": "{newsMetaData.news.description}",
"dateCreated": "<f:format.date format="Y-m-d">{newsMetaData.news.creationDate}</f:format.date>",
"datePublished": "<f:format.date format="Y-m-d">{newsMetaData.news.creationDate}</f:format.date>",
"dateModified": "<f:format.date format="Y-m-d">{newsMetaData.news.lastUpdated}</f:format.date>"
</f:section>
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
}, },
"suggest": { "suggest": {
"sgalinski/sg-ajax": "Required for the like feature", "sgalinski/sg-ajax": "Required for the like feature",
"sgalinski/sg-comments": "Flexible comments system" "sgalinski/sg-comments": "Flexible comments system",
"sgalinski/sg-seo": "For additional SEO features"
}, },
"replace": { "replace": {
"sgalinski/sg_news": "self.version" "sgalinski/sg_news": "self.version"
......
...@@ -28,7 +28,8 @@ $EM_CONF['sg_news'] = [ ...@@ -28,7 +28,8 @@ $EM_CONF['sg_news'] = [
'conflicts' => [], 'conflicts' => [],
'suggests' => [ 'suggests' => [
'sg_comments' => '6.0.0', 'sg_comments' => '6.0.0',
'sg_ajax' => '4.0.0' 'sg_ajax' => '4.0.0',
'sg_seo' => ''
], ],
], ],
'suggests' => [], 'suggests' => [],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment