5

We have many Views and Views displays. Over 3 years of building the site we have many displays that are not being used. We would like to delete them and clean up the view but are concerned that a display might be used in the site. Is there a way of determining if a views display is being used on the site? I thought of different ways to check this:

  1. A View display that is a Page will have a URL path. Check the path to see if it is working.
  2. A View display that is a block display will be in Managed Blocks. Go to Managed Blocks and see if is placed in any region.
  3. You can look at the view display machine name. And see if there are any twig templates that match that name.
  4. Also do a grep search in our templates for the display machine name to check if it printed in a twig template.
4
  • 1
    Great question, I'd guess it's been asked many times in the past as well. If nothing else, it demonstrates the value of a well-documented development process. My guess is that the answer is going to look like the one you've provided, i.e. a list of techniques rather than a definitive answer. The other technique is to disable views until you find out that you need them.
    – Alan Dixon
    Nov 18 '19 at 15:46
  • Our client would not like a View to be broken on Production. So we have to be certain which display can be deleted. Nov 18 '19 at 16:18
  • Would it be possible to implement a Views hook or template_preprocess_views_view() on a development copy of the site? Use a site crawler on the dev site to go to every page, or enough pages/depths, and save the name and/or id of the views and displays somewhere (text file, database, etc). Also use "Views::getAllViews()" along with $view->storage->get('display') to create a second list of all views/displays. Finally, use a SQL query or diff the files to see which views/displays weren't... viewed/displayed during the crawl. Nov 18 '19 at 20:10
  • What version of Drupal? 7 vs 8 makes a big difference here.
    – mpdonadio
    Nov 19 '19 at 2:15
2

If this is in Drupal 8, you can export all config and search for the display id in both code and config and you should be able to find if it is being used anywhere.

2
  • Thank you. I did not think about doing it this way. Nov 19 '19 at 14:04
  • Glad it helped!
    – anoopjohn
    Nov 19 '19 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.