You are here

function _slick_views_get_view_names in Slick Views 7.3

Utility function to get available Views using Slick Views style plugins.

1 call to _slick_views_get_view_names()
slick_views_update_7301 in ./slick_views.install
Update the deprecated Slick Views options to migrate from Slick 2.x to 3.x.

File

./slick_views.install, line 64
Installation actions for Slick Views.

Code

function _slick_views_get_view_names() {
  if (!db_table_exists('views_view')) {
    return [];
  }

  // Cannot query from database as views may be stored in code.
  // Cannot use vid as nothing in database when stored in code.
  $views = ctools_export_crud_load_all('views_view', TRUE);
  $names = [];
  foreach ($views as $view) {
    if (!empty($view->display)) {
      foreach ($view->display as $display) {
        $display_options = isset($display->display_options) ? $display->display_options : [];
        if ($display_options) {

          // 1. Collect all slick views ids.
          if (isset($display_options['style_plugin']) && $display_options['style_plugin'] == 'slick') {
            $names[] = $view->name;
          }
          elseif (isset($display_options['fields'])) {
            foreach ($display_options['fields'] as $field_display) {
              if (isset($field_display['type']) && $field_display['type'] == 'slick') {
                $names[] = $view->name;
              }
            }
          }
        }
      }
    }
  }
  $names = $names ? array_values(array_unique($names)) : [];

  // In order for the update to work, we must save exports into database so that
  // we have a View ID (vid) to work with.
  if ($names) {
    foreach ($names as $name) {
      $view = ctools_export_crud_load('views_view', $name);
      ctools_export_crud_save('views_view', $view);
    }
  }
  unset($views);
  return $names;
}