Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am building a site using openatrium.
One of the feature modules in openatrium contains a view ("atrium_members") that I would like to disable.
Is it possible to disable a view programmatically?
Of course, I could disable the view manually. But I'm trying to avoid manual intervention, if possible.
Thanks.
Comments
Comment #1
dawehnerin theory
Comment #2
kobnim CreditAttribution: kobnim commentedWorks like a charm. Thank you!
Comment #3
dawehnerSo
Comment #5
leex CreditAttribution: leex commentedD7 disabling using hooks, not variables:
The following would enable the default taxonom_term view, to disable an already enabled view, change FALSE to TRUE, depending on what other modules are doing, you may need to weight your module heavier to get the results you need.
With regards to ENABLING views in code: The problem with using variables is that if you're setting it in a module on install for example, there is no way to reliably remove the variable setting later (to disable the view) without knowing which other modules are using the view.
Here we're saying we'd like this view enabled, but once the module is disabled the view will go back to it's default state (disabled) if nothing else is using it.
Comment #6
karopka CreditAttribution: karopka commentedI have view with two attachment displays.
Can you show how to programmatically disable one display from a view?
Comment #7
joco_sp CreditAttribution: joco_sp commentedI'm using D7.
#1 worked for me.
#5 didn't.
Comment #8
a.milkovskyFYI: How to disable or enable views page programmatically?
Comment #9
janusman CreditAttribution: janusman commentedThis worked for me under D7 (from http://www.snip2code.com/Snippet/165083/Drupal-disable-a-Views-view-prog... )
When disabled, it shows up grayed out in the /admin/structure/views page. And changing the last 'TRUE' to 'FALSE' and re-running the above re-enables it.
Comment #10
TechNikh CreditAttribution: TechNikh commentedIf anyone is looking to disable a display of a view and not the entire view, below code worked for me
Comment #11
jedihe CreditAttribution: jedihe as a volunteer commented#9 worked for me (D7).
Comment #12
chOP CreditAttribution: chOP as a volunteer commentedFor anyone searching the issue queue for an answer to this, take a look at this Forum post:
How to disable or enable views page programmatically?
Comment #13
swirtComment #9 from Janusman worked so well I expanded it into a release in Module: Hook Update Deploy Tools so others can call it an get validation on the results in a hook_update_n()
https://www.drupal.org/node/2720425
Comment #14
mon623 CreditAttribution: mon623 commentedI am new to Drupal8 and didn't understand where to place the code mentioned in #9. Can anyone please help me out? I had disabled some views related to ubercart module and now i am not able to login to the backend. I get Unexpected error message. And the log files show this exception
[Mon Sep 26 16:13:32.409313 2016] [:error] [pid 11696:tid 1856] [client ::1:59358] Uncaught PHP Exception Symfony\\Component\\Routing\\Exception\\RouteNotFoundException: "Route "view.uc_cart_links.report" does not exist." at C:\\xampp\\htdocs\\drupal-final\\core\\lib\\Drupal\\Core\\Routing\\RouteProvider.php line 187
Will enabling the views solve this issue? If yes then where and how can i enable them?
Thanks
Comment #15
TunprogYou can disable views programmatically in D7 like this: