function views_get_applicable_views

Same name in other branches
  1. 6.x-3.x views.module \views_get_applicable_views()

Get applicable views.

Return a list of all views and display IDs that have a particular setting in their display's plugin settings.

Return value

array An array with the following structure. array( array($view, $display_id), array($view, $display_id), );

1 call to views_get_applicable_views()
views_menu_alter in ./views.module
Implements hook_menu_alter().

File

./views.module, line 1559

Code

function views_get_applicable_views($type) {
    // @todo Use a smarter flagging system so that we don't have to
    // load every view for this.
    $result = array();
    $views = views_get_all_views(TRUE);
    foreach ($views as $view) {
        // Skip disabled views.
        if (!empty($view->disabled)) {
            continue;
        }
        if (empty($view->display)) {
            // Skip this view as it is broken.
            vsm(t("Skipping broken view @view", array(
                '@view' => $view->name,
            )));
            continue;
        }
        // Loop on array keys because something seems to muck with $view->display
        // a bit in PHP4.
        foreach (array_keys($view->display) as $id) {
            $plugin = views_fetch_plugin_data('display', $view->display[$id]->display_plugin);
            if (!empty($plugin[$type])) {
                // This view uses hook menu. Clone it so that different handlers
                // don't trip over each other, and add it to the list.
                $v = $view->clone_view();
                if ($v->set_display($id) && $v->display_handler
                    ->get_option('enabled')) {
                    $result[] = array(
                        $v,
                        $id,
                    );
                }
                // In PHP 4.4.7 and presumably earlier, if we do not unset $v
                // here, we will find that it actually overwrites references
                // possibly due to shallow copying issues.
                unset($v);
            }
        }
    }
    return $result;
}