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

[4.x] Add ability to customize bard/replicator set icons directory #8931

Merged
merged 41 commits into from
Nov 15, 2023

Conversation

jesseleite
Copy link
Member

@jesseleite jesseleite commented Nov 3, 2023

This PR adds ability for user to customize bard/replicator set icons directory in a service provider.

Usage

Choose a different icon set for bard/replicator set icons...

\Statamic\Fieldtypes\Sets::setIconsDirectory(folder: 'light');

Choose a different base directory altogether...

\Statamic\Fieldtypes\Sets::setIconsDirectory(directory: resource_path('custom-icons'));

Todo

  • Add helper to set custom base directory and/or icon set sub-folder in service provider
  • Wire up to icon selector dropdowns in blueprint editor
  • Wire up to tabs and sections in blueprint editor
  • Wire up to the set picker used in bard/replicator fields on publish forms
  • Tests

@jasonvarga jasonvarga changed the title Add ability to customize bard/replicator set icon directory [4.x] Add ability to customize bard/replicator set icon directory Nov 8, 2023
@jesseleite jesseleite changed the title [4.x] Add ability to customize bard/replicator set icon directory [4.x] Add ability to customize bard/replicator set icons directory Nov 11, 2023
@jesseleite jesseleite marked this pull request as ready for review November 11, 2023 05:56
@jackmcdade
Copy link
Member

Is it possible to choose the folder in a Blueprint as a field config? I didn't realize this would be an all-in ServiceProvider thing 🤔

@jesseleite
Copy link
Member Author

I actually had that implemented first (you can see it in my commit history here in this PR), but Jason backed me away from that implementation and suggested we should do the service provider thing instead.

There was problems with reading from the same bard blueprint config where you set the folder and use the custom icons, before having saved the config first. Would've required extra custom ajax. There was another problem too, but I forget what now. Happy to revisit 🤔

@jesseleite
Copy link
Member Author

Oh it's coming back to me... The other concern Jason had was that people probably wouldn't want separate icon folder configs for every bard or replicator in a large app. If they're pulling from a custom set of icons on one bard field, we figure they'll probably want those extra custom icons on all bards, without having to configure over and over.

@jackmcdade
Copy link
Member

Ah fair enough I totally get that. Good calls then!

Copy link
Member

@jackmcdade jackmcdade left a comment

Choose a reason for hiding this comment

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

It seems like the Bard Set Icons are broken with this PR.

Before, when I picked an icon it would save just the icon name without the subfolder.

sets:
  new_set_group:
    display: 'New Set Group'
    icon: addon-boxes-stack

Now it saves with the subdirectory on the Set level, so all existing icons are broken, and for some reason new ones don't render either, neither the group nor the set itself, even if i configure everything after checking this PR out. I can't figure out what the correct format is and none of them seem to work.

CleanShot 2023-11-11 at 11 30 23@2x

However, if I set dir in the AppServiceProvider, everything seems to work fine. 🤔

@jesseleite
Copy link
Member Author

Awkward yeah. Apparently I'm bad a coding at midnight on Fridays 🙈

@jesseleite jesseleite marked this pull request as draft November 11, 2023 18:25
@jesseleite jesseleite marked this pull request as ready for review November 13, 2023 22:31
@jesseleite jesseleite dismissed jackmcdade’s stale review November 13, 2023 22:32

Think it's fixed 🤞

Copy link
Member

@jackmcdade jackmcdade left a comment

Choose a reason for hiding this comment

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

Works great!

@jackmcdade jackmcdade merged commit 0ef15f0 into 4.x Nov 15, 2023
35 checks passed
@jackmcdade jackmcdade deleted the feature/bard-set-custom-icons branch November 15, 2023 14:59
@mytchallb
Copy link
Contributor

Adding notes on how to use:

To use, edit the the boot method in app/Providers/AppServiceProvider.php with the following

public function boot(): void
{
    // Statamic::script('app', 'cp');
    // Statamic::style('app', 'cp');

    \Statamic\Fieldtypes\Sets::setIconsDirectory(folder: 'light');
}

That will use the light folder within the icons folder. If you want to set a completely custom path you can do:

\Statamic\Fieldtypes\Sets::setIconsDirectory(directory: resource_path('path/to/your/icons'));
(The path starts from your resources folder).

Also only .svg icons are supported.

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

Successfully merging this pull request may close these issues.

3 participants