Esempio n. 1
0
 /**
  * Return a list of all calendar views.
  *
  * @return array
  *   A list of all calendar views.
  */
 public static function listCalendarViews()
 {
     $calendar_views = [];
     $views = Views::getEnabledViews();
     foreach ($views as $view) {
         $ve = $view->getExecutable();
         $ve->initDisplay();
         foreach ($ve->displayHandlers->getConfiguration() as $display_id => $display) {
             if ($display_id != 'default' && ($types = $ve->getStyle()->getPluginId() == 'calendar')) {
                 $index = $ve->id() . ':' . $display_id;
                 $calendar_views[$index] = ucfirst($ve->id()) . ' ' . strtolower($display['display_title']) . ' [' . $ve->id() . ':' . $display['id'] . ']';
             }
         }
     }
     return $calendar_views;
 }
Esempio n. 2
0
 /**
  * Tests that the views list does not use a pager.
  */
 public function testViewsListLimit()
 {
     // Check if we can access the main views admin page.
     $this->drupalGet('admin/structure/views');
     $this->assertResponse(200);
     $this->assertLink(t('Add view'));
     // Count default views to be subtracted from the limit.
     $views = count(Views::getEnabledViews());
     // Create multiples views.
     $limit = 51;
     $values = $this->config('views.view.test_view_storage')->get();
     for ($i = 1; $i <= $limit - $views; $i++) {
         $values['id'] = 'test_view_storage_new' . $i;
         unset($values['uuid']);
         $created = View::create($values);
         $created->save();
     }
     $this->drupalGet('admin/structure/views');
     // Check that all the rows are listed.
     $this->assertEqual(count($this->xpath('//tbody/tr[contains(@class,"views-ui-list-enabled")]')), $limit);
 }
Esempio n. 3
0
 /**
  * Tests the load wrapper/helper functions.
  */
 public function testLoadFunctions()
 {
     $this->enableModules(array('field', 'text', 'node'));
     $this->installConfig(array('node'));
     $storage = $this->container->get('entity.manager')->getStorage('view');
     // Test views_view_is_enabled/disabled.
     $archive = $storage->load('archive');
     $this->assertTrue(views_view_is_disabled($archive), 'views_view_is_disabled works as expected.');
     // Enable the view and check this.
     $archive->enable();
     $this->assertTrue(views_view_is_enabled($archive), ' views_view_is_enabled works as expected.');
     // We can store this now, as we have enabled/disabled above.
     $all_views = $storage->loadMultiple();
     // Test Views::getAllViews().
     $this->assertIdentical(array_keys($all_views), array_keys(Views::getAllViews()), 'Views::getAllViews works as expected.');
     // Test Views::getEnabledViews().
     $expected_enabled = array_filter($all_views, function ($view) {
         return views_view_is_enabled($view);
     });
     $this->assertIdentical(array_keys($expected_enabled), array_keys(Views::getEnabledViews()), 'Expected enabled views returned.');
     // Test Views::getDisabledViews().
     $expected_disabled = array_filter($all_views, function ($view) {
         return views_view_is_disabled($view);
     });
     $this->assertIdentical(array_keys($expected_disabled), array_keys(Views::getDisabledViews()), 'Expected disabled views returned.');
     // Test Views::getViewsAsOptions().
     // Test the $views_only parameter.
     $this->assertIdentical(array_keys($all_views), array_keys(Views::getViewsAsOptions(TRUE)), 'Expected option keys for all views were returned.');
     $expected_options = array();
     foreach ($all_views as $id => $view) {
         $expected_options[$id] = $view->label();
     }
     $this->assertIdentical($expected_options, $this->castSafeStrings(Views::getViewsAsOptions(TRUE)), 'Expected options array was returned.');
     // Test the default.
     $this->assertIdentical($this->formatViewOptions($all_views), $this->castSafeStrings(Views::getViewsAsOptions()), 'Expected options array for all views was returned.');
     // Test enabled views.
     $this->assertIdentical($this->formatViewOptions($expected_enabled), $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'enabled')), 'Expected enabled options array was returned.');
     // Test disabled views.
     $this->assertIdentical($this->formatViewOptions($expected_disabled), $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'disabled')), 'Expected disabled options array was returned.');
     // Test the sort parameter.
     $all_views_sorted = $all_views;
     ksort($all_views_sorted);
     $this->assertIdentical(array_keys($all_views_sorted), array_keys(Views::getViewsAsOptions(TRUE, 'all', NULL, FALSE, TRUE)), 'All view id keys returned in expected sort order');
     // Test $exclude_view parameter.
     $this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', 'archive')), 'View excluded from options based on name');
     $this->assertFalse(array_key_exists('archive:default', Views::getViewsAsOptions(FALSE, 'all', 'archive:default')), 'View display excluded from options based on name');
     $this->assertFalse(array_key_exists('archive', Views::getViewsAsOptions(TRUE, 'all', $archive->getExecutable())), 'View excluded from options based on object');
     // Test the $opt_group parameter.
     $expected_opt_groups = array();
     foreach ($all_views as $view) {
         foreach ($view->get('display') as $display) {
             $expected_opt_groups[$view->id()][$view->id() . ':' . $display['id']] = (string) t('@view : @display', array('@view' => $view->id(), '@display' => $display['id']));
         }
     }
     $this->assertIdentical($expected_opt_groups, $this->castSafeStrings(Views::getViewsAsOptions(FALSE, 'all', NULL, TRUE)), 'Expected option array for an option group returned.');
 }
 /**
  * @param null $last_check
  * @return array
  */
 private function checkViewsAccess($last_check = NULL)
 {
     $result = TRUE;
     $check_result_value = array();
     $timestamp = NULL;
     $views = \Drupal\views\Views::getEnabledViews();
     // Need review
     foreach ($views as $view) {
         $view_name = $view->get('originalId');
         $view_display = $view->get('display');
         // Access is set in display options of a display.
         foreach ($view_display as $display_name => $display) {
             if (isset($display['display_options']['access']) && $display['display_options']['access']['type'] == 'none') {
                 $check_result_value[$view_name][] = $display_name;
             }
         }
     }
     if (!empty($check_result_value)) {
         $result = FALSE;
     }
     return array('result' => $result, 'value' => $check_result_value);
 }