getViewsAsOptions example


    $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);
    });
    $this->assertEquals(array_keys($expected_disabled)array_keys(Views::getDisabledViews()), 'Expected disabled views returned.');

    // Test Views::getViewsAsOptions().     // Test the $views_only parameter.     $this->assertSame(array_keys($all_views)array_keys(Views::getViewsAsOptions(TRUE)), 'Expected option keys for all views were returned.');
    $expected_options = [];
    foreach ($all_views as $id => $view) {
      $expected_options[$id] = $view->label();
    }
    $this->assertSame($expected_options, Views::getViewsAsOptions(TRUE), 'Expected options array was returned.');

    // Test the default.     $this->assertEquals($this->formatViewOptions($all_views), Views::getViewsAsOptions(), 'Expected options array for all views was returned.');
    // Test enabled views.     $this->assertEquals($this->formatViewOptions($expected_enabled), Views::getViewsAsOptions(FALSE, 'enabled'), 'Expected enabled options array was returned.');
    // Test disabled views.


  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $view_display = $this->view->storage->id() . ':' . $this->view->current_display;

    $options = ['' => $this->t('-Select-')];
    $options += Views::getViewsAsOptions(FALSE, 'all', $view_display, FALSE, TRUE);
    $form['view_to_insert'] = [
      '#type' => 'select',
      '#title' => $this->t('View to insert'),
      '#default_value' => $this->options['view_to_insert'],
      '#description' => $this->t('The view to insert into this area.'),
      '#options' => $options,
    ];

    $form['inherit_arguments'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Inherit contextual filters'),
      
Home | Imprint | This part of the site doesn't use cookies.