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 Excerpt Tab extendable and make it simpler to handle #267

@alexander-schranz

Description

@alexander-schranz

This ticket is similar to #266. The #266 should be tackled before to discuss all things before we start with this one.


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

  if ($reflection->implementsInterface(ExcerptInterface::class)) {
-     $this->addField($metadata, 'excerptTitle');
-     $this->addField($metadata, 'excerptMore', 'string', ['length' => 64]);
-     $this->addField($metadata, 'excerptDescription', 'text');
-     $this->addField($metadata, 'excerptImageId', 'integer', [
-         'columnName' => 'excerptImageId',
-         '_custom' => [
-             'references' => [
-                 'entity' => MediaInterface::class,
-                 'field' => 'id',
-                 'onDelete' => 'SET NULL',
-             ],
-         ],
-     ]);

-     $this->addField($metadata, 'excerptIconId', 'integer', [
-         'columnName' => 'excerptIconId',
-         '_custom' => [
-             'references' => [
-                 'entity' => MediaInterface::class,
-                 'field' => 'id',
-                 'onDelete' => 'SET NULL',
-             ],
-         ],
-     ]);

+    $this->addField($metadata, 'excerptData', 'json', ['nullable' => false, 'options' => ['jsonb' => true]]);

     $this->addManyToMany($event, $metadata, 'excerptTags', TagInterface::class, 'tag_id');
     $this->addManyToMany($event, $metadata, 'excerptCategories', CategoryInterface::class, 'category_id');
  }

In this case we may change the content_excerpt.xml to put Excerpt again into ext/excerpt like we already done previosly in the page_excerpt.

To support this we extend the ExcerptNormalizer so the excerptData field get correctly returned under ['ext']['excerpt']

We can simplify the ExcerptInterface setExcerptData and getExcerptData could look like this:

interface ExcerptInterface
{
    public function getExcerptData(): array;

    public function setExcerptData(array $excerptData): void;

    /**
     * @return CategoryInterface[]
     */
    public function getExcerptCategories(): array;

    /**
     * @return int[]
     */
    public function getExcerptCategoryIds(): array;

    /**
     * @param CategoryInterface[] $excerptCategories
     */
    public function setExcerptCategories(array $excerptCategories): void;

    /**
     * @return TagInterface[]
     */
    public function getExcerptTags(): array;

    /**
     * @return string[]
     */
    public function getExcerptTagNames(): array;

    /**
     * @param TagInterface[] $excerptTags
     */
    public function setExcerptTags(array $excerptTags): void;
}

That way we can remove the different setters which are not required.


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_excerpt.xml it should add that new field and save it also to the excerptData 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>excerpt_seo</key>

    <properties>
        <property name="ext/excerpt/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