Skip to content

Conversation

popoplanter
Copy link
Contributor

@popoplanter popoplanter commented Oct 28, 2022

Q A
Bug fix? no
New feature? yes
BC breaks? no
License MIT
Documentation PR sulu/sulu-docs#

What's in this PR?

Adds the possibility to select icons with a new single_icon_selection content type, the possibility of multiple icon set providers (icomoon, files),and a simple search to help find the right icon.

Why?

A nice selection of icons and how they look is much more user friendly than previous solutions to manage icons such as having a text_line where the icon name is provided.

Example Usage

Add icon sets:

sulu_admin:
    icon_sets:
        iconfont: icomoon://%kernel.project_dir%/public/iconfont/selection.json # Path to the icomoon selection.json
        svgs: svg://%kernel.project_dir%/public/svgs # Path to the svgs folder

Use the new content type:

    <property name="icon" type="single_icon_selection">
        <meta>
            <title>Icon</title>
        </meta>

        <params>
            <param name="icon_set" value="iconfont"/>
        </params>
    </property>

Bildschirmfoto 2022-11-30 um 09 46 20

Bildschirmfoto 2022-11-30 um 09 46 15

Documentation: sulu/sulu-docs#840

To Do

  • Create a documentation PR
  • Add breaking changes to UPGRADE.md

@alexander-schranz
Copy link
Member

How would currently the configuration of the content type? How and who is loading the selection.json?

To be with the naming consistent we should go with single_icon_select as selection are normally resources selection and there exist no icon resource yet.

We should discuss how we make it possible to have multiple providers not only icomoon. Common usecase would be:

  • font awesome
  • tailwinds hero icons (directory just with svg's)
  • directory of twig icons for inline icon usage

How we handle if the selection.json and other required "provider" files can't be in the public directory maybe we need to stream this via a controller.

@alexander-schranz
Copy link
Member

alexander-schranz commented Nov 2, 2022

Maybe we need some configuration in the sulu_admin for this new field type:

sulu_admin:
   icon_sets:
       website:
           provider: icomoon
           options:
               selection_json: '%kernel.project_dir%/assets/website/selection.json'
       other:
           provider: fontawesome
<property type="single_icon_select">
    <params>
         <param name="icon_set" value="website"/>
    </params>
</property>

To get the information to the frontend we maybe need an additional controller. /admin/api/icons?icon_set=website: IconController.

@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Sulu label Nov 2, 2022
@alexander-schranz
Copy link
Member

As discussed I think the best would be that we reuse existing components like the https://github.com/sulu/sulu/blob/2.5/src/Sulu/Bundle/AdminBundle/Resources/js/containers/SingleListOverlay/README.md to fetch the icon resource from the controller. So you don't need todo any fetch / request and reuse existing loading strategies to load the list data for the icons.

For this we mostly need to create our own Adapter for lists via the listRegistry. But lets check what maybe @niklasnatter has as input here.

@alexander-schranz alexander-schranz changed the base branch from 2.5 to 2.6 November 11, 2022 09:36
@popoplanter popoplanter force-pushed the feature/icons branch 16 times, most recently from 7b72926 to 9d758ee Compare November 15, 2022 15:27
@popoplanter
Copy link
Contributor Author

@wachterjohannes @luca-rath @alexander-schranz I fixed the checks except for one node lint error that i don't know how to fix. Maybe you know how to fix it? also a code review needs to be made :) thank you

type Props = FieldTypeProps<?string>

@observer
export default class SingleIconSelect extends React.Component<Props> {
Copy link
Contributor

Choose a reason for hiding this comment

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

as this is implemented using a list overlay now, i guess it would be more consistent to call it SingleIconSelection (same for the name of the field type and content type). but i am not sure if you already talked about this and if there are good reasons to keep select

Copy link
Contributor

Choose a reason for hiding this comment

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

also, we should add basic test cases for the component before merging it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexander-schranz @niklasnatter we talked about that but i think this was before the implementation with lists... should we use select or selection? Also i would appreciate some help with the test cases...

Copy link
Contributor

Choose a reason for hiding this comment

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

you dont need to worry about the tests too much. if everything else works, i can add the test cases 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexander-schranz what about the naming? select or selection?

onClick?: (id: string | number, selected: boolean) => void,
};

export default class SingleIcon extends React.PureComponent<Props> {
Copy link
Contributor

Choose a reason for hiding this comment

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

as far as i see, this component is not used by the SingleIconSelect component directly (only indirectly via the IconAdapter).

therefore i would prefer to make this consistent to the MediaCardAdapter and call it IconCard and store it in a separate folder (components/IconCard)

Copy link
Contributor

Choose a reason for hiding this comment

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

also, we should add basic test cases for the component before merging it

import AbstractAdapter from './AbstractAdapter';

@observer
class IconAdapter extends AbstractAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to add basic test cases for the component

$icons = [];
$path = $iconSet['options']['path'];

// TODO maybe do this in a compilerpass to avoid file system access in the runtime
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think @alexander-schranz?

@popoplanter popoplanter force-pushed the feature/icons branch 7 times, most recently from 380d8b9 to 3b6a61f Compare November 29, 2022 09:29
@martinlagler martinlagler force-pushed the feature/icons branch 2 times, most recently from 1f63ad4 to f24b443 Compare March 31, 2025 06:52
Copy link
Member

@Prokyonn Prokyonn left a comment

Choose a reason for hiding this comment

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

I think it would make sense to move the iconSet from the content to the view array:

image

@martinlagler
Copy link
Contributor

@alexander-schranz @Prokyonn Now everything should be fine :D Please check again.

The preview of the selected Icon (like in the single_media_selection) is still open, but I would prefer to handle that another time...

@Prokyonn
Copy link
Member

Prokyonn commented May 13, 2025

@alexander-schranz @Prokyonn Now everything should be fine :D Please check again.

The preview of the selected Icon (like in the single_media_selection) is still open, but I would prefer to handle that another time...

Looks good 👍
@martinlagler can you create a pull request in https://github.com/sulu/sulu-docs for the documentation? (We also need an additional note then that this is only available for Sulu >= 2.6.9)

I think this is the last missing part to have this in the next release :)

Edit: and we should also update the description of this PR as it is really misleading, as the actual config looks completely different 😬

@martinlagler
Copy link
Contributor

@alexander-schranz @Prokyonn Now everything should be fine :D Please check again.
The preview of the selected Icon (like in the single_media_selection) is still open, but I would prefer to handle that another time...

Looks good 👍 @martinlagler can you create a pull request in https://github.com/sulu/sulu-docs for the documentation? (We also need an additional note then that this is only available for Sulu >= 2.6.9)

I think this is the last missing part to have this in the next release :)

Edit: and we should also update the description of this PR as it is really misleading, as the actual config looks completely different 😬

@Prokyonn
Done 😄
Description is updated and Documentation PR: sulu/sulu-docs#840

@alexander-schranz alexander-schranz changed the title FEATURE: Added icon selection Add icon selection field and content type May 14, 2025
@alexander-schranz alexander-schranz merged commit 65839cc into sulu:2.6 May 14, 2025
9 checks passed
@alexander-schranz
Copy link
Member

Thx @popoplanter, @0xJas0n, @martinlagler, @niklasnatter, @Prokyonn

@niklasnatter
Copy link
Contributor

Thx @popoplanter, @0xJas0n, @martinlagler, @niklasnatter, @Prokyonn

🥳

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 Sulu UX Affecting the end user
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants