-
Notifications
You must be signed in to change notification settings - Fork 132
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
Scope module assets ( v2 ) #487
Conversation
Even though this method was never implemented - deprecate it, in case someone is relying on it
Rename `disable_custom_statuses_for_post_type` to `is_module_edit_view`
…ngs_view( $this->module->name )
… fix-351-scope-assets
Instead of a plain `is_active_view()`
… fix-351-scope-assets
… fix-351-scope-assets
…w into scope-module-assets # Conflicts: # modules/calendar/calendar.php # modules/custom-status/custom-status.php # modules/editorial-comments/editorial-comments.php
Looks like tests need fixing, working on it... |
This fixes the test errors that happened after migrating most of the methods away from EF_Module to EF_Module_With_View Changed the class used in tests from `EF_Module` to `EF_Module_With_view` The test only tests a module with a view, not a generic Edit_Flow module.
Looks like this will have to wait a little bit. The tests caught a bug! 🎉 🎉 🎉 https://github.com/Automattic/Edit-Flow/pull/487/files#diff-228291de10e40133681b1ff8414a9a54L220 The code above will prevent EF from registering the post status if it's not the "View" page. That shouldn't be done in a "module view" but everywhere. Same applies for methods like Todo: |
Closing this for now, doesn't seem likely to get the merge button. I like the approach of doing this on a module-by-module basis, can certainly re-use much of what is here though. |
Previous PR (#441) history was messed up, re-creating it here with a better history:
Overview
At the moment, almost all assets are loaded on every admin page (for example -
calendar.js
is loaded in "Settings -> General”). Overall there were a lot of inconsistencies in asset enqueuing. The goal of this PR is to provide a reliable and predictable way of enqueuing module assets.Background
Every Edit Flow module extends the
EF_Module
class. However, some modules have dedicated views and some modules (like Dashboard widgets module) don’t. That’s where the inconsistencies begin.Most EF Modules enqueue assets. Some check whether they should enqueue assets, some perform the same checks in a different way, and some don’t check at all. Most of the modules use method
EF_Module::is_whitelisted_functional_view
which simply always returns true, with a//@todo
attached to it :) - the whole asset enqueuing process needed a refactor.Introducing
EF_Module_With_View
The EF modules needed a few methods to make it easy to check whether the any given module is visible at the moment (and therefore, whether they should enqueue assets). In most cases this is either in the edit, list and settings views.
At first I dumped all the necessary methods on
EF_Module
class because all of the modules already are extending it. ButEF_Module
is also instantiated directly and it’s also extended by aEF_Dashboard
class that doesn’t utilize the any of the “new” methods, so it didn’t make sense to keep them there.EF_Module_With_View extends EF_Module
and is meant to be extended further by modules that have views, that way they have access to necessary methods, likeis_current_module_settings_view()
andis_active_view()
Adding PHP interfaces
There was no streamlined way of dealing with assets. Even enqueuing method names varied from module to module. That’s why I decided to 2 simple interfaces:
EF_Script_Interface
andEF_Style_Interface
- they will ensure that asset enqueuing methods are consistent and predictable. Also, by reading the class declaration it’s immediately clear whether or not the current module is enqueuing any assets.Summary
EF_Module_With_View
that provides methods to easily determine whether or not assets are neededEF_Module_With_View
instead ofEF_Module
and enqueue assets when they’re neededFixes #351