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

[Example] Modify list and form of built-in category entity #92

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niklasnatter
Copy link
Contributor

@niklasnatter niklasnatter commented Feb 15, 2021

What's in this PR?

This PR demonstrates how to modify the list view and the form view of the the built-in category entity. The example hides the key property and adds an additional color property to the list view and form view of the category entity.

To implement the color property, the PR extends the category entity and adds a Symfony event listener to persist and serialize the data of the new property.

Screenshot 2021-02-15 at 14 21 31

To apply the changes, the schema of the database needs to be updated by executing bin/console doctrine:schema:update --force.

@niklasnatter niklasnatter force-pushed the example/modify-entity-list-form branch 2 times, most recently from f8cd428 to b72662e Compare February 15, 2021 13:08
@alexander-schranz alexander-schranz added the Example Example implementations label Feb 15, 2021
@niklasnatter niklasnatter marked this pull request as draft February 15, 2021 13:22
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>category_details</key>
Copy link
Contributor Author

@niklasnatter niklasnatter Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sulu automatically merges form-configurations that use the same key. This allows to hide existing properties and display new properties in existing forms.

To use this mechanism with form-configurations that include <section> tags, the workaround described in sulu/sulu#5570 might be helpful.

Be aware that newly added properties need to be persisted to the database and included in the responses of the respective API endpoints. For example, this is possible by implementing an event subscriber similar to the CategoryEventSubscriber in this PR.

@@ -0,0 +1,13 @@
<?xml version="1.0" ?>
<list xmlns="http://schemas.sulu.io/list-builder/list">
<key>categories</key>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sulu automatically merges list-configurations that use the same key. This allows to hide existing properties and display new properties in existing lists.

@niklasnatter niklasnatter force-pushed the example/modify-entity-list-form branch from b72662e to 1eb2fb6 Compare February 16, 2021 08:38
@niklasnatter niklasnatter force-pushed the example/modify-entity-list-form branch from 1eb2fb6 to 0a8cca3 Compare February 16, 2021 08:43
@rflorent
Copy link

Hello,
how to get the new property color on frontend when categories are used with pages ?
Thanks

@matthiasseghers
Copy link

@rflorent

You can get this by passing additional data to the controller.

@FlxRobole
Copy link

FlxRobole commented Jul 9, 2024

Thanks a lot! It would be quite interesting to know how to access the new color property in the items returned by twig-function sulu_categories (or when used via content-type category selection). As far as I can see the fields are mapped by CategoryWrapper which is called by CategoryManager::getApiObject(), but I have no idea how to "replace" or override the CategoryWrapper with my own (extended) wrapper. Only way out seems to be adding my own sulu_categories_with_colours twig-function...?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Example Example implementations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants