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

How this plugin handles paths #25

Merged
merged 20 commits into from
Nov 8, 2024
Merged

Conversation

Levdbas
Copy link
Collaborator

@Levdbas Levdbas commented Nov 5, 2024

Related:

There are still some todos before we can review this:

  • make the way the __construct() method is setup more flexible.
  • test icons in parent theme
  • test themes without a parent theme
  • test custom location override
  • set a path that is a sane default in acf_icon_path_suffix or the new filter that we will use instead.
  • Deprecate old filters
  • Rewrite readme file

Issue

The way you set paths, url's and directories via filters is not very handy.

Solution

Rewrite the way you can serve SVGs to this plugin.

Impact

High, users will have to use the new filters to keep using this new version. There will be a fallback for the most simple setups that will throw a deprecation notice.

Usage Changes

Some, but I will document that later.

Considerations

Might be a step too far, although I think this is way more flexible.

Testing

Not yet, something to consider later

@Levdbas Levdbas linked an issue Nov 5, 2024 that may be closed by this pull request
2 tasks
@Levdbas Levdbas marked this pull request as ready for review November 6, 2024 14:49
@Levdbas
Copy link
Collaborator Author

Levdbas commented Nov 6, 2024

Hi @mike-sheppard ,

PR is ready for review. I still have to document the changes. I also set up PHPunit tests that I do need to document as well in a contribution guide. If you want to lend a hand in this as well, feel free to do so.

New default theme location
We can discuss this, but I think this is a sane default: themes/my-theme/icons/

There are two new filters

For setting a custom folder inside your (parent)theme:

// will look into themes/my-theme/custom/icons/ for icons and also in the parent theme in the case of parent/child themes.
add_filter('acf_svg_icon_picker_folder', function () {
	return 'custom-icons/';
});

and for setting a complete custom location:

// takes a path and url location
add_filter('acf_svg_icon_picker_custom_location', function () {
	return [
		'path' => WP_CONTENT_DIR . '/random-location-icons/',
		'url' =>  content_url() . '/random-location-icons/',
	];
});

There are three new helper functions:
These can help plugin users to get the correct icons in parent/child theme setups. They wont currently work with custom location. But then again, if you are using a custom location, you can write your own getter function anyway.

SmithfieldStudio\AcfSvgIconPicker\get_svg_icon_uri(),
SmithfieldStudio\AcfSvgIconPicker\get_svg_icon_path() and
SmithfieldStudio\AcfSvgIconPicker\get_svg_icon()

@Levdbas Levdbas linked an issue Nov 6, 2024 that may be closed by this pull request
@Levdbas Levdbas mentioned this pull request Nov 6, 2024
@mike-sheppard
Copy link
Member

ah nice one @Levdbas all sounds great to me, will pull this down and give it a test later this week. Thanks again for the hard work on all of this 🙏

@mike-sheppard
Copy link
Member

hey @Levdbas tested this out, and it works perfectly. While digging around, I managed to fix an issue we have with hashed assets #26 - hoping this simplifies things a tiny bit 🤞

@Levdbas
Copy link
Collaborator Author

Levdbas commented Nov 8, 2024

We have automatic tests now @mike-sheppard 👯

@Levdbas
Copy link
Collaborator Author

Levdbas commented Nov 8, 2024

@mike-sheppard , can you do one last check on my readme changes and contribution guide? I documented there how to run the tests locally.

@Levdbas Levdbas changed the title (WIP ) How this plugin handles paths How this plugin handles paths Nov 8, 2024
Copy link
Member

@mike-sheppard mike-sheppard left a comment

Choose a reason for hiding this comment

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

Nice one! Left a few minor comments + still need to get my tests running locally

CONTRIBUTING.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Co-authored-by: Mike Sheppard <[email protected]>
@Levdbas
Copy link
Collaborator Author

Levdbas commented Nov 8, 2024

@mike-sheppard , shall I invite you to a quick Teams call to get the tests running? Or else we can schedule something for next week.

@mike-sheppard
Copy link
Member

All tests passing 🎉 I'll quickly add a test to my branch for the extra function added, test + merge back here for you to release when ready 🙏

2024-11-08 1738 - iTerm2@2x

* Add support for hashed assets

1. This hopefully simplifies our checks a bit as we're already gathering most of this info within `svg_collector()`, so we shouldn't need to check again.

2. By saving the full path in `svg_collector()` we can provide support for hashed assets eg. `arrow-left.524a72.svg`

```php
"arrow left" => [
    "name" => "arrow left"
    "filename" => "arrow-left.524a72"
    "icon" => "arrow-left.524a72.svg"
    "url" => "/dist/editor/images/icons/admin-picker/arrow-left.524a72.svg"
]
```

3. Also, might be better to save an ID (`sanitize_key($name)`) of the icon to the ACF field instead of the name?

* Fix filters

* Use sanitized key for ACF field val instead 'name'

* Bring back normalized title in filter

* Fix icon array check

* Support legacy field values

* README tweaks - add filters + release links

* Fix phpcs config, igmore `*/wp-content/*`

* Add missing void return type

* Move js, css & extract views into resources

* Add composer aliases/nicknames

* Fix silly typos

* Add Test: check sanitised and legacy (unsanitised) acf values
* Add missing return types + simplify acf field view phpstan issues

* Fix logic typo + encode plus symbol

* Update versions
Copy link
Member

@mike-sheppard mike-sheppard left a comment

Choose a reason for hiding this comment

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

Reckon this is good to go whenever you're happy to merge! 🙌

@Levdbas Levdbas merged commit a046667 into main Nov 8, 2024
6 checks passed
@Levdbas Levdbas deleted the 22-how-this-plugin-handles-paths branch November 8, 2024 20:20
@Levdbas
Copy link
Collaborator Author

Levdbas commented Nov 8, 2024

Merged! @mike-sheppard , can you do a changelog update as well before deploying the update? Probably emphasize a bit on the deprecated filters and the new way of saving the file names. Enjoy the weekend and amazing work!

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.

How this plugin handles paths. Add Unit tests.
2 participants