-
Notifications
You must be signed in to change notification settings - Fork 40
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
Move default views to their respective modules #361
Comments
Tried to have a crack at this, but simply moving the taxonomy and comment view config files to their respective modules didn't seem to work... Do you have to register config files somewhere? |
You shouldn't have to. Just putting the In order to get the "Revert" option working in the View UI, you'll also need to update the "module" key in the JSON config file to point at the original module. |
I created a new site based on this code and nothing seems to have changed... If I disable AND uninstall the Comment module, then refresh the Views overview page, the Recent Comments default view is still present. However when I then try to enable it, I get a whole bunch of errors about |
Hmm... If the view hasn't been enabled and is in the default state, it seems like we should remove it doesn't it? We could add a check into hook_uninstall() for Taxonomy and Comment module to check if this is the case and clean up the installed views if they are in the default state. Modified Views should probably be left in place and left to the user to delete. You can check by checking the "storage" property in the JSON file: $config = config('views.view.comments_recent');
if ($config->get('storage') == VIEWS_STORAGE_DEFAULT) {
$config->delete();
}
This is acceptable IMO. It's the same behavior you'd get with any view if you disabled a module after using its fields or filters anywhere. We actually have the same behavior in Layouts (the block shows up as "Broken" and is still there, but can be removed). |
It's been a long time coming, but I just made a new PR for this issue (no, I haven't been working on it all these years 😝). |
...I have reviewed the PR and it seems good code-wise, but when testing in the PR sandbox I have noticed that the "Recent comments" view was still available even when the Comments module was disabled and uninstalled. I would expect that:
|
...I forgot to mention that before disabling and uninstalling the module, I had also reverted the view. |
...on second thought, point 2 in my comment above makes sense only in the case of contrib modules, AND specifically when the module files have been removed from the codebase. In case of core modules (which are always present in the codebase), I would expect that enabling a disabled view would ask you to also enable the module providing it. But I realise that we do not have any such logic in place, so perhaps a follow-up issue? |
I noticed the same. I think it may have to do with the 'storage' config option not always being available...? |
Based on this comment in
I've gone ahead and changed the PR to delete views on uninstall if the view has not been overridden (as opposed to if it's in default state). This is because, as far as I can tell, unless a module-provided view has been overridden, the 'storage' option may not exist. We can therefore assume that it's in its default state, since we know it's a module-provided view (as opposed to a user-created one, which would have a 'normal' state). In other words, I simply changed |
Not sure that this works as expected quite yet. I have tested this in the PR sandbox:
|
I agree that we can do things better regarding disabled modules, etc., but I wonder what the scope of this issue is... If it's simply to move the views out of Views and into their respective modules, then maybe we should create a separate issue for @klonos' suggestions. If we want this issue to be inclusive of those suggestions though, I'll try looking at this later to see what can be done. |
I am a fan of "baby steps" ...so we can have a separate issue for improving the handling of views provided by modules. That's why in my initial review comment a few days back I said:
It was my way of saying that the PR is RTBC for its scope (moving the code). The other things I have reported are pre-existing issues anyway. |
We should fix the problem @klonos described above, where Comment and Taxonomy modules will only take ownership of their views on new installs instead of existing ones. We need an update hook in both modules that just loads in their corresponding view config files, updates the |
One question, should we include views.view.promoted in this PR? |
Into Node module?
…On Sat, Mar 2, 2019 at 10:49 AM Herb ***@***.***> wrote:
One question, should we include views.view.promoted in this PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I think yes |
It does seem weird that |
I've moved the promoted view to the node module, and added an update hook to switch the module from |
Looks like tests aren't passing because of views_install() referencing the promoted view config file. |
Do you think I need to move the old update hook?
edit: Oh, `views_install()` not `views.install`! checking...
|
Hm, views install doesn't reference the old config file: /**
* Implements hook_install().
*/
function views_install() {
db_query("UPDATE {system} SET weight = 10 WHERE name = 'views'");
} Here's what's in /**
* Replace the frontpage view with promoted.
*/
function views_update_1004() {
// If the old frontpage view is still disabled, delete it.
if (config_get('views.view.frontpage', 'disabled') === TRUE) {
$config_frontpage = config('views.view.frontpage');
$config_frontpage->delete();
}
// See if there is already a promoted view on this site.
$config_promoted = config('views.view.promoted');
if ($config_promoted->isNew()) {
// If not, create the new promoted view and mark it disabled.
$path = backdrop_get_path('module', 'views') . '/config/';
$contents = file_get_contents($path . 'views.view.promoted.json');
$data = json_decode($contents, true);
$config_promoted->setData($data);
$config_promoted->set('disabled', TRUE);
$config_promoted->save();
}
} I'll try changing the module to node, but is it okay to leave this update in views module? |
Yes. Though we shouldn't actually be doing this at all. This is why we copy the entire view into update hooks, and why we have an issue at #3347. Update hooks shouldn't be dependent upon the default configuration of a module, because that default configuration changes over time. |
By @BWPanda, @jenlampton, and @klonos.
Thanks @jenlampton for the quick update! I've merged backdrop/backdrop#2464 into 1.x for 1.13.0. Thanks @BWPanda, @klonos, and @herbdool for your work here! |
As per #147 (comment), default views should be provided by their module and not Views itself.
PR by @BWPanda: backdrop/backdrop#2391PR by @jenlampton backdrop/backdrop#2464
The text was updated successfully, but these errors were encountered: