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

TYPO3-Headless / headless / 9988298871

18 Jul 2024 08:38AM UTC coverage: 66.922% (+1.2%) from 65.741%
9988298871

push

github

web-flow
[FEATURE] Introduce support of SEO related APIs from TYPO3 Core (#752)

Patch introduces proper support of SEO related settings & APIs in TYPO3 core:

Patch adds ability to use:
- Canonical API
- MetaTag API
- Page title API

Respects `page.meta` TypoScript definitions.

59 of 60 new or added lines in 2 files covered. (98.33%)

1050 of 1569 relevant lines covered (66.92%)

2.83 hits per line

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

97.14
/Classes/Seo/MetaTag/AbstractMetaTagManager.php
1
<?php
2

3
/*
4
 * This file is part of the "headless" Extension for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.md file that was distributed with this source code.
8
 */
9

10
declare(strict_types=1);
11

12
namespace FriendsOfTYPO3\Headless\Seo\MetaTag;
13

14
use FriendsOfTYPO3\Headless\Utility\HeadlessMode;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16

17
use function array_merge;
18
use function json_decode;
19
use function json_encode;
20

21
/**
22
 * Overridden core version with headless implementation
23
 */
24
abstract class AbstractMetaTagManager extends \TYPO3\CMS\Core\MetaTag\AbstractMetaTagManager
25
{
26
    public function renderAllProperties(): string
27
    {
28
        if (GeneralUtility::makeInstance(HeadlessMode::class)->withRequest($GLOBALS['TYPO3_REQUEST'])->isEnabled()) {
2✔
29
            return $this->renderAllHeadlessProperties();
2✔
30
        }
31

32
        return parent::renderAllProperties();
1✔
33
    }
34

35
    public function renderProperty(string $property): string
36
    {
37
        if (GeneralUtility::makeInstance(HeadlessMode::class)->withRequest($GLOBALS['TYPO3_REQUEST'])->isEnabled()) {
1✔
38
            return $this->renderHeadlessProperty($property);
1✔
39
        }
40

41
        return parent::renderProperty($property);
1✔
42
    }
43

44
    /**
45
     * Render a meta tag for a specific property
46
     *
47
     * @param string $property Name of the property
48
     */
49
    public function renderHeadlessProperty(string $property): string
50
    {
51
        $property = strtolower($property);
2✔
52
        $metaTags = [];
2✔
53

54
        $nameAttribute = $this->defaultNameAttribute;
2✔
55
        if (isset($this->handledProperties[$property]['nameAttribute'])
2✔
56
            && !empty((string)$this->handledProperties[$property]['nameAttribute'])) {
2✔
57
            $nameAttribute = (string)$this->handledProperties[$property]['nameAttribute'];
1✔
58
        }
59

60
        $contentAttribute = $this->defaultContentAttribute;
2✔
61
        if (isset($this->handledProperties[$property]['contentAttribute'])
2✔
62
            && !empty((string)$this->handledProperties[$property]['contentAttribute'])) {
2✔
NEW
63
            $contentAttribute = (string)$this->handledProperties[$property]['contentAttribute'];
×
64
        }
65

66
        if ($nameAttribute && $contentAttribute) {
2✔
67
            foreach ($this->getProperty($property) as $propertyItem) {
2✔
68
                $metaTags[] = [
2✔
69
                    htmlspecialchars($nameAttribute) => htmlspecialchars($property),
2✔
70
                    htmlspecialchars($contentAttribute) => htmlspecialchars($propertyItem['content']),
2✔
71
                ];
2✔
72

73
                if (!count($propertyItem['subProperties'])) {
2✔
74
                    continue;
2✔
75
                }
76
                foreach ($propertyItem['subProperties'] as $subProperty => $subPropertyItems) {
1✔
77
                    foreach ($subPropertyItems as $subPropertyItem) {
1✔
78
                        $metaTags[] = [
1✔
79
                            htmlspecialchars($nameAttribute) => htmlspecialchars($property . $this->subPropertySeparator . $subProperty),
1✔
80
                            htmlspecialchars($contentAttribute) => htmlspecialchars((string)$subPropertyItem),
1✔
81
                        ];
1✔
82
                    }
83
                }
84
            }
85
        }
86

87
        return json_encode($metaTags);
2✔
88
    }
89

90
    /**
91
     * Render all registered properties of this manager
92
     */
93
    public function renderAllHeadlessProperties(): string
94
    {
95
        $metatags = [];
2✔
96
        foreach (array_keys($this->properties) as $property) {
2✔
97
            $metatags = array_merge($metatags, json_decode($this->renderHeadlessProperty($property), true));
2✔
98
        }
99

100
        return json_encode($metatags);
2✔
101
    }
102
}
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

© 2025 Coveralls, Inc