• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / Yoast-SEO-for-TYPO3 / 13120606731

03 Feb 2025 06:47PM UTC coverage: 1.297%. Remained the same
13120606731

push

github

RinyVT
[FEATURE] Added Reading Time and Word Count to the Insights

35 of 2698 relevant lines covered (1.3%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/Service/TcaService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace YoastSeoForTypo3\YoastSeo\Service;
6

7
use TYPO3\CMS\Core\Information\Typo3Version;
8
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10

11
class TcaService
12
{
13
    protected const LL_PREFIX_TCA = 'LLL:EXT:yoast_seo/Resources/Private/Language/TCA.xlf:';
14
    protected const LL_PREFIX_BACKEND = 'LLL:EXT:yoast_seo/Resources/Private/Language/BackendModule.xlf:';
15

16
    protected string $table = '';
17
    protected string $types = '';
18
    protected string $descriptionField = '';
19

20
    public function addYoastFields(string $table, string $types, string $descriptionField = 'description'): void
21
    {
22
        $this->table = $table;
×
23
        $this->types = $types;
×
24
        $this->descriptionField = $descriptionField;
×
25

26
        $this->addDefaultFields();
×
27

28
        $this->addPalettes();
×
29
        $this->addToTypes();
×
30
    }
31

32
    protected function addDefaultFields(): void
33
    {
34
        $columns = [
×
35
            'tx_yoastseo_snippetpreview' => [
×
36
                'label' => self::LL_PREFIX_BACKEND . 'snippetPreview',
×
37
                'exclude' => true,
×
38
                'displayCond' => 'FIELD:tx_yoastseo_hide_snippet_preview:REQ:false',
×
39
                'config' => [
×
40
                    'type' => 'none',
×
41
                    'renderType' => 'snippetPreview',
×
42
                    'settings' => [
×
43
                        'titleField' => 'seo_title',
×
44
                        'descriptionField' => $this->descriptionField,
×
45
                    ],
×
46
                ],
×
47
            ],
×
48
            'tx_yoastseo_readability_analysis' => [
×
49
                'label' => self::LL_PREFIX_BACKEND . 'analysis',
×
50
                'exclude' => true,
×
51
                'displayCond' => 'FIELD:tx_yoastseo_hide_snippet_preview:REQ:false',
×
52
                'config' => [
×
53
                    'type' => 'none',
×
54
                    'renderType' => 'readabilityAnalysis',
×
55
                ],
×
56
            ],
×
57
            'tx_yoastseo_focuskeyword' => [
×
58
                'label' => self::LL_PREFIX_BACKEND . 'seoFocusKeyword',
×
59
                'exclude' => true,
×
60
                'displayCond' => 'FIELD:tx_yoastseo_hide_snippet_preview:REQ:false',
×
61
                'config' => [
×
62
                    'type' => 'input',
×
63
                ],
×
64
            ],
×
65
            'tx_yoastseo_focuskeyword_analysis' => [
×
66
                'label' => self::LL_PREFIX_BACKEND . 'analysis',
×
67
                'exclude' => true,
×
68
                'displayCond' => 'FIELD:tx_yoastseo_hide_snippet_preview:REQ:false',
×
69
                'config' => [
×
70
                    'type' => 'none',
×
71
                    'renderType' => 'focusKeywordAnalysis',
×
72
                    'settings' => [
×
73
                        'focusKeywordField' => 'tx_yoastseo_focuskeyword',
×
74
                    ],
×
75
                ],
×
76
            ],
×
77
            'tx_yoastseo_cornerstone' => [
×
78
                'label' => '',
×
79
                'exclude' => true,
×
80
                'config' => [
×
81
                    'type' => 'input',
×
82
                    'default' => 0,
×
83
                    'renderType' => 'cornerstone',
×
84
                ],
×
85
            ],
×
86
            'tx_yoastseo_score_readability' => [
×
87
                'label' => '',
×
88
                'exclude' => false,
×
89
                'config' => [
×
90
                    'type' => 'passthrough',
×
91
                ],
×
92
            ],
×
93
            'tx_yoastseo_score_seo' => [
×
94
                'label' => '',
×
95
                'exclude' => false,
×
96
                'config' => [
×
97
                    'type' => 'passthrough',
×
98
                ],
×
99
            ],
×
100
            'tx_yoastseo_focuskeyword_related' => [
×
101
                'label' => self::LL_PREFIX_TCA . 'pages.fields.tx_yoastseo_focuskeyword_related',
×
102
                'exclude' => true,
×
103
                'config' => [
×
104
                    'type' => 'inline',
×
105
                    'foreign_table' => 'tx_yoastseo_related_focuskeyword',
×
106
                    'foreign_field' => 'uid_foreign',
×
107
                    'foreign_table_field' => 'tablenames',
×
108
                    'maxitems' => 5,
×
109
                ],
×
110
            ],
×
111
            'tx_yoastseo_insights' => [
×
112
                'exclude' => true,
×
113
                'config' => [
×
114
                    'type' => 'none',
×
115
                    'renderType' => 'insights',
×
116
                ],
×
117
            ],
×
118
            'tx_yoastseo_focuskeyword_synonyms' => [
×
119
                'label' => self::LL_PREFIX_TCA . 'synonyms',
×
120
                'exclude' => true,
×
121
                'displayCond' => 'FIELD:tx_yoastseo_hide_snippet_preview:REQ:false',
×
122
                'config' => [
×
123
                    'type' => 'input',
×
124
                ],
×
125
            ],
×
126
            'tx_yoastseo_robots_noimageindex' => [
×
127
                'label' => self::LL_PREFIX_TCA . 'pages.fields.robots.noimageindex',
×
128
                'exclude' => true,
×
129
                'config' => [
×
130
                    'type' => 'check',
×
131
                    'renderType' => 'checkboxToggle',
×
132
                    'items' => $this->getInvertedCheckbox(),
×
133
                ],
×
134
            ],
×
135
            'tx_yoastseo_robots_noarchive' => [
×
136
                'label' => self::LL_PREFIX_TCA . 'pages.fields.robots.noarchive',
×
137
                'exclude' => true,
×
138
                'config' => [
×
139
                    'type' => 'check',
×
140
                    'renderType' => 'checkboxToggle',
×
141
                    'items' => $this->getInvertedCheckbox(),
×
142
                ],
×
143
            ],
×
144
            'tx_yoastseo_robots_nosnippet' => [
×
145
                'label' => self::LL_PREFIX_TCA . 'pages.fields.robots.nosnippet',
×
146
                'exclude' => true,
×
147
                'config' => [
×
148
                    'type' => 'check',
×
149
                    'renderType' => 'checkboxToggle',
×
150
                    'items' => $this->getInvertedCheckbox(),
×
151
                ],
×
152
            ],
×
153
        ];
×
154
        if ($this->table === 'pages') {
×
155
            $columns['tx_yoastseo_hide_snippet_preview'] = [
×
156
                'label' => self::LL_PREFIX_BACKEND . 'hideSnippetPreview',
×
157
                'exclude' => true,
×
158
                'config' => [
×
159
                    'type' => 'check',
×
160
                ],
×
161
            ];
×
162
        }
163
        ExtensionManagementUtility::addTCAcolumns(
×
164
            $this->table,
×
165
            $columns
×
166
        );
×
167
    }
168

169
    protected function addPalettes(): void
170
    {
171
        ExtensionManagementUtility::addFieldsToPalette(
×
172
            $this->table,
×
173
            'seo',
×
174
            '--linebreak--, tx_yoastseo_snippetpreview, --linebreak--',
×
175
            'before: seo_title'
×
176
        );
×
177

178
        ExtensionManagementUtility::addFieldsToPalette(
×
179
            $this->table,
×
180
            'seo',
×
181
            '--linebreak--, ' . $this->descriptionField . ', --linebreak--, tx_yoastseo_cornerstone',
×
182
            'after: seo_title'
×
183
        );
×
184

185
        ExtensionManagementUtility::addFieldsToPalette(
×
186
            $this->table,
×
187
            'yoast-readability',
×
188
            '--linebreak--, tx_yoastseo_readability_analysis'
×
189
        );
×
190

191
        ExtensionManagementUtility::addFieldsToPalette(
×
192
            $this->table,
×
193
            'yoast-focuskeyword',
×
194
            '--linebreak--, tx_yoastseo_focuskeyword,
×
195
            --linebreak--, tx_yoastseo_focuskeyword_synonyms,
196
            --linebreak--, tx_yoastseo_focuskeyword_analysis'
×
197
        );
×
198

199
        ExtensionManagementUtility::addFieldsToPalette(
×
200
            $this->table,
×
201
            'yoast-relatedkeywords',
×
202
            '--linebreak--, tx_yoastseo_focuskeyword_related '
×
203
        );
×
204

205
        ExtensionManagementUtility::addFieldsToPalette(
×
206
            $this->table,
×
207
            'yoast-insights',
×
208
            '--linebreak--, tx_yoastseo_insights'
×
209
        );
×
210

211
        ExtensionManagementUtility::addFieldsToPalette(
×
212
            $this->table,
×
213
            'yoast-advanced-robots',
×
214
            '--linebreak--, tx_yoastseo_robots_noimageindex,tx_yoastseo_robots_noarchive,tx_yoastseo_robots_nosnippet'
×
215
        );
×
216

217
        ExtensionManagementUtility::addFieldsToPalette(
×
218
            $this->table,
×
219
            'yoast-advanced',
×
220
            '--linebreak--, tx_yoastseo_hide_snippet_preview'
×
221
        );
×
222
    }
223

224
    protected function addToTypes(): void
225
    {
226
        ExtensionManagementUtility::addToAllTCAtypes(
×
227
            $this->table,
×
228
            '--palette--;Label;yoast-snippetpreview,',
×
229
            $this->types,
×
230
            'before:seo_title'
×
231
        );
×
232

233
        ExtensionManagementUtility::addToAllTCAtypes(
×
234
            $this->table,
×
235
            '--palette--;' . self::LL_PREFIX_TCA . 'pages.palettes.readability;yoast-readability,
×
236
            --palette--;' . self::LL_PREFIX_TCA . 'pages.palettes.focusKeyphrase;yoast-focuskeyword,
×
237
            --palette--;' . self::LL_PREFIX_TCA . 'pages.palettes.focusRelatedKeyphrases;yoast-relatedkeywords,
×
238
            --palette--;' . self::LL_PREFIX_TCA . 'pages.palettes.insights;yoast-insights,',
×
239
            $this->types,
×
240
            'after: tx_yoastseo_cornerstone'
×
241
        );
×
242

243
        ExtensionManagementUtility::addToAllTCAtypes(
×
244
            $this->table,
×
245
            '--palette--;' . self::LL_PREFIX_TCA . 'pages.palettes.robots;yoast-advanced-robots,',
×
246
            $this->types,
×
247
            'after:no_follow'
×
248
        );
×
249

250
        ExtensionManagementUtility::addToAllTCAtypes(
×
251
            $this->table,
×
252
            '--palette--;' . self::LL_PREFIX_TCA . 'pages.palettes.advances;yoast-advanced,',
×
253
            $this->types,
×
254
            'after: twitter_image'
×
255
        );
×
256
    }
257

258
    /**
259
     * @return array<array<int|string, string|bool>>
260
     */
261
    protected function getInvertedCheckbox(): array
262
    {
263
        if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() >= 12) {
×
264
            return [
×
265
                [
×
266
                    1 => '',
×
267
                    'invertStateDisplay' => true,
×
268
                    'label' => '',
×
269
                ],
×
270
            ];
×
271
        }
272
        return [
×
273
            [
×
274
                0 => '',
×
275
                1 => '',
×
276
                'invertStateDisplay' => true,
×
277
            ],
×
278
        ];
×
279
    }
280
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc