[TASK] Remove canonical link if noindex 00/58600/6
authorGianluigi Martino <gmartino27@gmail.com>
Tue, 9 Oct 2018 11:37:19 +0000 (13:37 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 28 Oct 2018 13:15:42 +0000 (14:15 +0100)
Some frontend and backend optimizations for canonical links

- Change position of canonical link input field in backend
- Hide canonical link input if in backend "no_index" toggle is inactive
- Reload page by changing "no_index" toggle in backend

Resolves: #86515
Releases: master
Change-Id: I70dd8e36ada7c1a4c9b5aec7f69866eae0592945
Reviewed-on: https://review.typo3.org/58600
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Kummer <typo3@enobe.de>
Tested-by: Joerg Kummer <typo3@enobe.de>
Reviewed-by: Felix Althaus <felix.althaus@undkonsorten.com>
Tested-by: Felix Althaus <felix.althaus@undkonsorten.com>
Reviewed-by: Richard Haeser <richard@maxserv.com>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/seo/Classes/Canonical/CanonicalGenerator.php
typo3/sysext/seo/Configuration/TCA/Overrides/pages.php

index 43b6c4e..f7a5157 100644 (file)
@@ -91,9 +91,9 @@ class CanonicalGenerator
 
         if (!empty($href)) {
             $canonical = '<link ' . GeneralUtility::implodeAttributes([
-                'rel' => 'canonical',
-                'href' => $href
-            ], true) . '/>' . LF;
+                    'rel' => 'canonical',
+                    'href' => $href
+                ], true) . '/>' . LF;
             $this->typoScriptFrontendController->additionalHeaderData[] = $canonical;
             return $canonical;
         }
index f899925..4d15c9f 100644 (file)
@@ -11,6 +11,10 @@ $tca = [
             'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.palettes.robots',
             'showitem' => 'no_index;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_index_formlabel, no_follow;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_follow_formlabel',
         ],
+        'canonical' => [
+            'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.palettes.canonical',
+            'showitem' => 'canonical_link',
+        ],
         'opengraph' => [
             'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.palettes.opengraph',
             'showitem' => 'og_title, --linebreak--, og_description, --linebreak--, og_image',
@@ -19,10 +23,6 @@ $tca = [
             'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.palettes.twittercards',
             'showitem' => 'twitter_title, --linebreak--, twitter_description, --linebreak--, twitter_image',
         ],
-        'canonical' => [
-            'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.palettes.canonical',
-            'showitem' => 'canonical_link',
-        ],
     ],
     'columns' => [
         'seo_title' => [
@@ -39,6 +39,7 @@ $tca = [
         'no_index' => [
             'exclude' => true,
             'l10n_mode' => 'exclude',
+            'onChange' => 'reload',
             'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.no_index',
             'config' => [
                 'type' => 'check',
@@ -68,6 +69,28 @@ $tca = [
                 ]
             ]
         ],
+        'canonical_link' => [
+            'exclude' => true,
+            'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link',
+            'displayCond' => 'FIELD:no_index:=:0',
+            'config' => [
+                'type' => 'input',
+                'renderType' => 'inputLink',
+                'size' => 50,
+                'max' => 1024,
+                'eval' => 'trim',
+                'fieldControl' => [
+                    'linkPopup' => [
+                        'options' => [
+                            'title' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link',
+                            'blindLinkFields' => 'class,target,title',
+                            'blindLinkOptions' => 'mail,folder,file'
+                        ],
+                    ],
+                ],
+                'softref' => 'typolink'
+            ]
+        ],
         'og_title' => [
             'exclude' => true,
             'l10n_mode' => 'prefixLangTitle',
@@ -166,27 +189,6 @@ $tca = [
                 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
             )
         ],
-        'canonical_link' => [
-            'exclude' => true,
-            'label' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link',
-            'config' => [
-                'type' => 'input',
-                'renderType' => 'inputLink',
-                'size' => 50,
-                'max' => 1024,
-                'eval' => 'trim',
-                'fieldControl' => [
-                    'linkPopup' => [
-                        'options' => [
-                            'title' => 'LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.canonical_link',
-                            'blindLinkFields' => 'class,target,title',
-                            'blindLinkOptions' => 'mail,folder,file'
-                        ],
-                    ],
-                ],
-                'softref' => 'typolink'
-            ]
-        ],
     ],
 ];
 
@@ -197,17 +199,10 @@ $GLOBALS['TCA']['pages'] = array_replace_recursive($GLOBALS['TCA']['pages'], $tc
     --div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.seo,
         --palette--;;seo,
         --palette--;;robots,
-        --palette--;;canonical,',
-    (string)\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT,
-    'after:title'
-);
-
-\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
-    'pages',
-    '
+        --palette--;;canonical,
     --div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.socialmedia,
         --palette--;;opengraph,
-        --palette--;;twittercards,',
+        --palette--;;twittercards',
     (string)\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT,
-    'after:canonical_link'
+    'after:title'
 );