當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Views::getViewsAsOptions方法代碼示例

本文整理匯總了PHP中Drupal\views\Views::getViewsAsOptions方法的典型用法代碼示例。如果您正苦於以下問題:PHP Views::getViewsAsOptions方法的具體用法?PHP Views::getViewsAsOptions怎麽用?PHP Views::getViewsAsOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\views\Views的用法示例。


在下文中一共展示了Views::getViewsAsOptions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildOptionsForm

 /**
  * {@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.'));
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:12,代碼來源:View.php

示例2: testLoadFunctions

 /**
  * 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.');
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:59,代碼來源:ModuleTest.php

示例3: buildOptionsForm

 /**
  * {@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;
 }
開發者ID:darrylri,項目名稱:protovbmwmo,代碼行數:40,代碼來源:View.php


注:本文中的Drupal\views\Views::getViewsAsOptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。