Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $view_display = $this->view->storage->id() . ':' . $this->view->current_display;
     $options = array('' => $this->t('-Select-'));
     $options += Views::getViewsAsOptions(FALSE, 'all', $view_display, FALSE, TRUE);
     $form['view_to_insert'] = array('#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'] = array('#type' => 'checkbox', '#title' => $this->t('Inherit contextual filters'), '#default_value' => $this->options['inherit_arguments'], '#description' => $this->t('If checked, this view will receive the same contextual filters as its parent.'));
 }
Exemplo n.º 2
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.');
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildOptionsForm(&$form, FormStateInterface $form_state)
 {
     parent::buildOptionsForm($form, $form_state);
     $view_options = Views::getViewsAsOptions(TRUE, 'all', NULL, FALSE, TRUE);
     $form['views_field_view'] = ['#type' => 'details', '#title' => $this->t("View settings"), '#open' => TRUE];
     $form['view'] = ['#type' => 'select', '#title' => $this->t('View'), '#description' => $this->t('Select a view to embed.'), '#default_value' => $this->options['view'], '#options' => $view_options, '#ajax' => ['path' => views_ui_build_form_url($form_state)], '#submit' => [[$this, 'submitTemporaryForm']], '#executes_submit_callback' => TRUE, '#fieldset' => 'views_field_view'];
     // If there is no view set, use the first one for now.
     if (count($view_options) && empty($this->options['view'])) {
         $new_options = array_keys($view_options);
         $this->options['view'] = reset($new_options);
     }
     if ($this->options['view']) {
         $view = Views::getView($this->options['view']);
         $display_options = [];
         foreach ($view->storage->get('display') as $name => $display) {
             // Allow to embed a different display as the current one.
             if ($this->options['view'] != $this->view->storage->id() || $this->view->current_display != $name) {
                 $display_options[$name] = $display['display_title'];
             }
         }
         $form['display'] = ['#type' => 'select', '#title' => $this->t('Display'), '#description' => $this->t('Select a view display to use.'), '#default_value' => $this->options['display'], '#options' => $display_options, '#ajax' => ['path' => views_ui_build_form_url($form_state)], '#submit' => [[$this, 'submitTemporaryForm']], '#executes_submit_callback' => TRUE, '#fieldset' => 'views_field_view'];
         // Provide a way to directly access the views edit link of the child view.
         // Don't show this link if the current view is the selected child view.
         if (!empty($this->options['view']) && !empty($this->options['display']) && $this->view->storage->id() != $this->options['view']) {
             // use t() here, and set HTML on #link options.
             $link_text = $this->t('Edit "%view (@display)" view', ['%view' => $view_options[$this->options['view']], '@display' => $this->options['display']]);
             $form['view_edit'] = ['#type' => 'container', '#fieldset' => 'views_field_view'];
             $form['view_edit']['view_edit_link'] = ['#type' => 'link', '#title' => $link_text, '#url' => Url::fromRoute('entity.view.edit_display_form', ['view' => $this->options['view'], 'display_id' => $this->options['display']], ['attributes' => ['target' => '_blank', 'class' => ['views-field-view-child-view-edit']], 'html' => TRUE]), '#attached' => ['library' => ['views_field_view/drupal.views_field_view']], '#prefix' => '<span>[</span>', '#suffix' => '<span>]</span>'];
             $form['view_edit']['description'] = ['#markup' => $this->t('Use this link to open the current child view\'s edit page in a new window.'), '#prefix' => '<div class="description">', '#suffix' => '</div>'];
         }
         $form['arguments'] = ['#title' => $this->t('Contextual filters'), '#description' => $this->t('Use a comma (,) or forwardslash (/) separated list of each contextual filter which should be forwared to the view.
       See below list of available replacement tokens. Static values are also be passed to child views if they do not match a token format.
       You could pass static ID\'s or taxonomy terms in this way. E.g. 123 or "my taxonomy term".'), '#type' => 'textfield', '#default_value' => $this->options['arguments'], '#fieldset' => 'views_field_view'];
         $form['available_tokens'] = ['#type' => 'details', '#title' => $this->t('Replacement patterns'), '#value' => $this->getTokenInfo(), '#fieldset' => 'views_field_view'];
     }
     $form['alter']['#access'] = FALSE;
 }