5

I created a clone of a view and have completely forgotten why I did that.

I suspect that I was experimenting, but before I delete the view, I want to make sure that it is not being used.

Is there a mechanism by which one can list where views are being used?

3 Answers 3

1

Open the View and you'll see if it is a page or block, if it is a page you can see the path to the page under Page Settings, if it is a block just look for that block in the list (/admin/structure/block).

The block is named like Views:[view_name] and if it is disabled I think you can safely remove that View, if not you can see the region and where you can see that block when you edit block and look at Visibility settings.

I think that there is no other automated way to find out where some View is used.

2
  • but if someone manually called a block using custom code then how can you find it in regions area?
    – WaQaR Ali
    Aug 10, 2015 at 5:06
  • WaQaR Ali asks a great question. In my case, there is no custom coding. This answer is a head-slapper - I should have figured this out. Thank you.
    – GRoston
    Aug 11, 2015 at 3:33
1

I have a tricky solution for you we know that the hook_views_pre_render called right before the renderprocessSo we just need put a dpm $view->name and just need visit all your pages and write down the views name that getting run, after that delete the other ones you create and not used any where.

update : more deatils about creating custom moudle

create a directory "my_module" then create 3 file in it

  • my_module.info
  • my_module.module
  • my_module.views.inc

fill the below codes in them

my_module.info

name = My Module
description = Behold my awesome module.
core = 7.x
package = Other

my_module.module

<?php
/**
 * Implements hook_views_api().
 */
function my_module_views_api() {
  return array(
    'api' => 3, 
    'path' => drupal_get_path('module', 'my_module'), 
    'template path' => drupal_get_path('module', 'my_module'),
  );
}

my_module.views.inc

function my_module_views_pre_render(&$view){
   dpm($view->name);
}

put the directory in site/all/modules then go to admin/modules and find and enable it (Also enable devel module)

2
  • I will assume that this is a correct answer, but it is beyond my skill level. I believe that the answer provided by mixerowsky will get the job done.
    – GRoston
    Aug 11, 2015 at 3:31
  • @GRoston I update my question with more details
    – Yuseferi
    Aug 11, 2015 at 6:31
0

There are 3 cases which you may use a View (I omitted the Panels)

  • as a block
  • as a page
  • load the View by some functions like views_embed_view()

@mixerowsky told you how to check for the first and the second one. for the third option you can use the following code to to check every file (or at least .php file) inside your theme directory and see if the View name is used in there or not. If it is used then see if it is loaded via some functions or not

$di = new RecursiveDirectoryIterator('./');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
    if((strpos($filename,'.php') != false)){
        $file_data .= file_get_contents($filename);
        if(strpos($file_data,'THE_VIEW_NAME') != false)
            echo $filename . ' - ' . $file->getSize() . ' bytes <br/>';
    }
}

Put this code in a .php file and put it in any directory that you need to search for files content. This code will loop in every file and subfolders of that directory.

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.