getAllViews example

$form['subquery_namespace'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Subquery namespace'),
      '#description' => $this->t('Advanced. Enter a namespace for the subquery used by this relationship.'),
      '#default_value' => $this->options['subquery_namespace'],
    ];

    // WIP: This stuff doesn't work yet: namespacing issues.     // A list of suitable views to pick one as the subview.     $views = ['' => '- None -'];
    foreach (Views::getAllViews() as $view) {
      // Only get views that are suitable:       // - base must the base that our relationship joins towards       // - must have fields.       if ($view->get('base_table') == $this->definition['base'] && !empty($view->getDisplay('default')['display_options']['fields'])) {
        // TODO: check the field is the correct sort?         // or let users hang themselves at this stage and check later?         $views[$view->id()] = $view->id();
      }
    }

    $form['subquery_view'] = [
      
    $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().     ksort($all_views);
    $this->assertEquals(array_keys($all_views)array_keys(Views::getAllViews()), 'Views::getAllViews works as expected.');

    // Test Views::getEnabledViews().     $expected_enabled = array_filter($all_viewsfunction D$view) {
      return views_view_is_enabled($view);
    });
    $this->assertEquals(array_keys($expected_enabled)array_keys(Views::getEnabledViews()), 'Expected enabled views returned.');

    // Test Views::getDisabledViews().     $expected_disabled = array_filter($all_viewsfunction D$view) {
      return views_view_is_disabled($view);
    });
    
Home | Imprint | This part of the site doesn't use cookies.