Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Excerpt Tab extendable and make it simpler to handle #267

Open
alexander-schranz opened this issue Aug 9, 2024 · 0 comments
Open
Labels
Feature New functionality not yet included in Bundle

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Aug 9, 2024

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

@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Bundle label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Bundle
Projects
None yet
Development

No branches or pull requests

1 participant