clickstorm / cs_seo

[clickstorm] SEO
Other
33 stars 49 forks source link

php Warning #314

Closed mikeemike7 closed 1 year ago

mikeemike7 commented 1 year ago

Hi there, using cs_seo unter PHP 8.1 seams to cause php warnings, e. g. "PHP Warning: Trying to access array offset on value of type null in /www/...../ext/cs_seo/Classes/Service/HrefLangService.php line 34"

How can I fix that? (Using: Typo3 V 11.5.27, cs_seo 7.3.2)

Best regards, Mike

ilomedia commented 1 year ago

Hi,

similar problem with PHP 8.2.7 :

Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1476107295: PHP Warning: Undefined array key "currentUrl." in /typo3conf/ext/cs_seo/Classes/Service/CanonicalService.php line 32 | TYPO3\CMS\Core\Error\Exception thrown in file /var/www/html/SMENO/2020.smeno.com/public/typo3/sysext/core/Classes/Error/ErrorHandler.php in line 137

mhirdes commented 1 year ago

Did you include the TypoScript from the extension?

mikeemike7 commented 1 year ago

oh yes, sure I did and included the TypoScript.

mhirdes commented 1 year ago

but then there should be no error

mhirdes commented 1 year ago

In line 32 $typoLinkConf = $this->typoScriptFrontendController->tmpl->setup['lib.']['currentUrl.']['typolink.'];

So if you included the TypoScritp lib.currentUrl should be defined with cs_seo/Configuration/TypoScript/Setup/lib.currenUrl.typoscript

Please check your TypoScript

mhirdes commented 1 year ago

You can also contact me on Slack and we take a look together

kanow commented 1 year ago

Attached patch helps to fix that warning in php > 8

mmh.. can't attach my patch file.Wrong file type? .patch

Here directly the code.

Index: Classes/Service/HrefLangService.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Classes/Service/HrefLangService.php b/Classes/Service/HrefLangService.php
--- a/Classes/Service/HrefLangService.php   
+++ b/Classes/Service/HrefLangService.php   (date 1692266489192)
@@ -31,7 +31,7 @@
         /** @var ContentObjectRenderer $cObj */
         $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
         $context = GeneralUtility::makeInstance(Context::class);
-        $typoLinkConf = $GLOBALS['TSFE']->tmpl->setup['lib.']['currentUrl.']['typolink.'];
+        $typoLinkConf = $GLOBALS['TSFE']->tmpl->setup['lib.']['currentUrl.']['typolink.'] ?? [];
         $tempLinkVars = $GLOBALS['TSFE']->linkVars;

         // remove config.linkVars temporary
Index: Classes/Service/CanonicalService.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Classes/Service/CanonicalService.php b/Classes/Service/CanonicalService.php
--- a/Classes/Service/CanonicalService.php  
+++ b/Classes/Service/CanonicalService.php  (date 1692266459732)
@@ -29,7 +29,7 @@
         /** @var ContentObjectRenderer $cObj */
         $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
         $context = GeneralUtility::makeInstance(Context::class);
-        $typoLinkConf = $this->typoScriptFrontendController->tmpl->setup['lib.']['currentUrl.']['typolink.'];
+        $typoLinkConf = $this->typoScriptFrontendController->tmpl->setup['lib.']['currentUrl.']['typolink.'] ?? [];
         $tempLinkVars = $this->typoScriptFrontendController->linkVars;

         // remove config.linkVars temporary

Save that as .patch file and use composer to patch it. Then your warning should be gone. In our case we had the TypoScript included but setup will be deleted in part of the newsletter page tree. We don't need that seo stuff in the newsletter.

mhirdes commented 1 year ago

Then you also don't need a hreflang on this page. Would be better to turn it off. When a href lang should be outputet, then the lib.currentUrl should be available.