WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Make SEO Tab extendable and make it simpler to handle #266

@alexander-schranz

Description

@alexander-schranz

The SEO Tab should be extendable over XML mechanism of Sulu. At current state create a lot of unneeded SEO fields which we could also store as JSON object we already do for template data. The only field which is required for filtering is currently the seoHideInSitemap all other fields we could store into a JSON field:

 if ($reflection->implementsInterface(SeoInterface::class)) {
-    $this->addField($metadata, 'seoTitle');
-    $this->addField($metadata, 'seoDescription', 'text');
-    $this->addField($metadata, 'seoKeywords', 'text');
+    $this->addField($metadata, 'seoData', 'json', ['nullable' => false, 'options' => ['jsonb' => true]]);
-    $this->addField($metadata, 'seoCanonicalUrl', 'text');
-    $this->addField($metadata, 'seoNoIndex', 'boolean');
-    $this->addField($metadata, 'seoNoFollow', 'boolean');
     $this->addField($metadata, 'seoHideInSitemap', 'boolean');
+    $this->addIndex($metadata, 'idx_seo_hide_in_sitemap', ['seoHideInSitemap']);
 }

In this case we may change the content_seo.xml to put SEO again into ext/seo like we already done previosly in the page_seo. This may also resolve the SERP currently not working: #79

To support this we need introduce also a SeoNormalizer so the seoData field get correctly returned under ['ext']['seo']: https://github.com/sulu/SuluContentBundle/tree/0.8.1/Content/Application/ContentNormalizer/Normalizer So Seo fields are not returned on the root level instead again under ext/seo.

The setSeoData and getSeoData could look like this:

public function setSeoData(array $seoData): void {
    if (\array_key_exists('hideInSitemap', $seoData)) {
         $this->seoHideInSitemap = $seoData['hideInSitemap'];
         
         unset($seoData);
    }
    
    $this->seoData = $seoData;
}

public function getSeoData(): {
    $seoData = $this->seoData;
    $seoData['hideInSitemap'] = $this->seoHideInSitemap;
    
    return $seoData
}

That way we can remove the different setters.


The change is a BC break and require a SQL upgrade in the UPGRADE.md.


The exptected result is if somebody creates inside of its own project a config/form/content_seo.xml it should add that new field and save it also to the seoData json field:

<?xml version="1.0" ?>
<form xmlns="http://schemas.sulu.io/template/template"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd"
>
    <key>content_seo</key>

    <properties>
        <property name="ext/seo/custom" type="text_line">
            <meta>
                <title>Custom Field</title>
            </meta>
        </property>
    </properties>
</form>

We may could add should add to our test application such file: https://github.com/sulu/SuluContentBundle/tree/0.8.1/Tests/Application/config and test it in the ExampleTestController

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew functionality not yet included in Bundle

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions