当前位置: 首页>>代码示例>>PHP>>正文


PHP Entity\View类代码示例

本文整理汇总了PHP中Drupal\views\Entity\View的典型用法代码示例。如果您正苦于以下问题:PHP View类的具体用法?PHP View怎么用?PHP View使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了View类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testFilterUI

 /**
  * Tests the filter UI.
  */
 public function testFilterUI()
 {
     $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
     $result = $this->xpath('//select[@id="edit-options-value"]/option');
     // Ensure that the expected hierarchy is available in the UI.
     $counter = 0;
     for ($i = 0; $i < 3; $i++) {
         for ($j = 0; $j <= $i; $j++) {
             $option = $result[$counter++];
             $prefix = $this->terms[$i][$j]->parent->target_id ? '-' : '';
             $attributes = $option->attributes();
             $tid = (string) $attributes->value;
             $this->assertEqual($prefix . $this->terms[$i][$j]->getName(), (string) $option);
             $this->assertEqual($this->terms[$i][$j]->id(), $tid);
         }
     }
     // Ensure the autocomplete input element appears when using the 'textfield'
     // type.
     $view = View::load('test_filter_taxonomy_index_tid');
     $display =& $view->getDisplay('default');
     $display['display_options']['filters']['tid']['type'] = 'textfield';
     $view->save();
     $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
     $this->assertFieldByXPath('//input[@id="edit-options-value"]');
     // Tests \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::calculateDependencies().
     $expected = ['config' => ['taxonomy.vocabulary.tags'], 'content' => ['taxonomy_term:tags:' . Term::load(2)->uuid()], 'module' => ['node', 'taxonomy', 'user']];
     $this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:31,代码来源:TaxonomyIndexTidUiTest.php

示例2: testUsername

 /**
  * Test the username formatter.
  */
 public function testUsername()
 {
     $view_id = $this->randomMachineName();
     $view = View::create(['id' => $view_id, 'base_table' => 'comment_field_data', 'display' => ['default' => ['display_plugin' => 'default', 'id' => 'default', 'display_options' => ['fields' => ['name' => ['table' => 'comment_field_data', 'field' => 'name', 'id' => 'name', 'plugin_id' => 'field', 'type' => 'comment_username'], 'subject' => ['table' => 'comment_field_data', 'field' => 'subject', 'id' => 'subject', 'plugin_id' => 'field', 'type' => 'string', 'settings' => ['link_to_entity' => TRUE]]]]]]]);
     $view->save();
     /* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
     $account_switcher = \Drupal::service('account_switcher');
     /* @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $account_switcher->switchTo($this->adminUser);
     $executable = Views::getView($view_id);
     $build = $executable->preview();
     $this->setRawContent($renderer->renderRoot($build));
     $this->verbose($this->getRawContent());
     $this->assertLink('My comment title');
     $this->assertLink('Anonymous comment title');
     $this->assertLink($this->adminUser->label());
     $this->assertLink('barry (not verified)');
     $account_switcher->switchTo(new AnonymousUserSession());
     $executable = Views::getView($view_id);
     $executable->storage->invalidateCaches();
     $build = $executable->preview();
     $this->setRawContent($renderer->renderRoot($build));
     // No access to user-profiles, so shouldn't be able to see links.
     $this->assertNoLink($this->adminUser->label());
     // Note: External users aren't pointing to drupal user profiles.
     $this->assertLink('barry (not verified)');
     $this->verbose($this->getRawContent());
     $this->assertLink('My comment title');
     $this->assertLink('Anonymous comment title');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:34,代码来源:CommentUserNameTest.php

示例3: assertFieldAccess

 /**
  * Checks views field access for a given entity type and field name.
  *
  * To use this method, set up an entity of type $entity_type_id, with field
  * $field_name. Create an entity instance that contains content $field_content
  * in that field.
  *
  * This method will check that a user with permission can see the content in a
  * view, and a user without access permission on that field cannot.
  *
  * @param string $entity_type_id
  *   The entity type ID.
  * @param string $field_name
  *   The field name.
  * @param string $field_content
  *   The expected field content.
  */
 protected function assertFieldAccess($entity_type_id, $field_name, $field_content)
 {
     \Drupal::state()->set('views_field_access_test-field', $field_name);
     $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
     $view_id = $this->randomMachineName();
     $data_table = $entity_type->getDataTable();
     // Use the data table as long as the field is not 'uuid'. This is the only
     // column that can only be obtained from the base table.
     $base_table = $data_table && $field_name !== 'uuid' ? $data_table : $entity_type->getBaseTable();
     $entity = View::create(['id' => $view_id, 'base_table' => $base_table, 'display' => ['default' => ['display_plugin' => 'default', 'id' => 'default', 'display_options' => ['fields' => [$field_name => ['table' => $base_table, 'field' => $field_name, 'id' => $field_name, 'plugin_id' => 'field']]]]]]);
     $entity->save();
     /** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
     $account_switcher = \Drupal::service('account_switcher');
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $account_switcher->switchTo($this->userWithAccess);
     $executable = Views::getView($view_id);
     $build = $executable->preview();
     $this->setRawContent($renderer->renderRoot($build));
     $this->assertText($field_content);
     $this->assertTrue(isset($executable->field[$field_name]));
     $account_switcher->switchTo($this->userWithoutAccess);
     $executable = Views::getView($view_id);
     $build = $executable->preview();
     $this->setRawContent($renderer->renderRoot($build));
     $this->assertNoText($field_content);
     $this->assertFalse(isset($executable->field[$field_name]));
     \Drupal::state()->delete('views_field_access_test-field');
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:46,代码来源:FieldFieldAccessTestBase.php

示例4: testUI

 public function testUI()
 {
     // Set up a block and a entity_test entity.
     $block = Block::create(['id' => 'test_id', 'plugin' => 'system_main_block']);
     $block->save();
     $entity_test = EntityTest::create(['bundle' => 'entity_test']);
     $entity_test->save();
     $default = $this->randomView([]);
     $id = $default['id'];
     $view = View::load($id);
     $this->drupalGet($view->urlInfo('edit-form'));
     // Add a global NULL argument to the view for testing argument placeholders.
     $this->drupalPostForm("admin/structure/views/nojs/add-handler/{$id}/page_1/argument", ['name[views.null]' => 1], 'Add and configure contextual filters');
     $this->drupalPostForm(NULL, [], 'Apply');
     // Configure both the entity_test area header and the block header to
     // reference the given entities.
     $this->drupalPostForm("admin/structure/views/nojs/add-handler/{$id}/page_1/header", ['name[views.entity_block]' => 1], 'Add and configure header');
     $this->drupalPostForm(NULL, ['options[target]' => $block->id()], 'Apply');
     $this->drupalPostForm("admin/structure/views/nojs/add-handler/{$id}/page_1/header", ['name[views.entity_entity_test]' => 1], 'Add and configure header');
     $this->drupalPostForm(NULL, ['options[target]' => $entity_test->id()], 'Apply');
     $this->drupalPostForm(NULL, [], 'Save');
     // Confirm the correct target identifiers were saved for both entities.
     $view = View::load($id);
     $header = $view->getDisplay('default')['display_options']['header'];
     $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
     $this->assertEqual($block->id(), $header['entity_block']['target']);
     $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
     // Confirm that the correct serial ID (for the entity_test) and config ID
     // (for the block) are displayed in the form.
     $this->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block");
     $this->assertFieldByName('options[target]', $block->id());
     $this->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test");
     $this->assertFieldByName('options[target]', $entity_test->id());
     // Replace the header target entities with argument placeholders.
     $this->drupalPostForm("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply');
     $this->drupalPostForm("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test", ['options[target]' => '{{ raw_arguments.null }}'], 'Apply');
     $this->drupalPostForm(NULL, [], 'Save');
     // Confirm that the argument placeholders are saved.
     $view = View::load($id);
     $header = $view->getDisplay('default')['display_options']['header'];
     $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
     $this->assertEqual('{{ raw_arguments.null }}', $header['entity_block']['target']);
     $this->assertEqual('{{ raw_arguments.null }}', $header['entity_entity_test']['target']);
     // Confirm that the argument placeholders are still displayed in the form.
     $this->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block");
     $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
     $this->drupalGet("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test");
     $this->assertFieldByName('options[target]', '{{ raw_arguments.null }}');
     // Change the targets for both headers back to the entities.
     $this->drupalPostForm("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_block", ['options[target]' => $block->id()], 'Apply');
     $this->drupalPostForm("admin/structure/views/nojs/handler/{$id}/page_1/header/entity_entity_test", ['options[target]' => $entity_test->id()], 'Apply');
     $this->drupalPostForm(NULL, [], 'Save');
     // Confirm the targets were again saved correctly and not skipped based on
     // the previous form value.
     $view = View::load($id);
     $header = $view->getDisplay('default')['display_options']['header'];
     $this->assertEqual(['entity_block', 'entity_entity_test'], array_keys($header));
     $this->assertEqual($block->id(), $header['entity_block']['target']);
     $this->assertEqual($entity_test->uuid(), $header['entity_entity_test']['target']);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:60,代码来源:AreaEntityUITest.php

示例5: testViewsPostUpdateBooleanFilterValues

 /**
  * Tests that boolean filter values are updated properly.
  */
 public function testViewsPostUpdateBooleanFilterValues()
 {
     $this->runUpdates();
     // Load and initialize our test view.
     $view = View::load('test_boolean_filter_values');
     $data = $view->toArray();
     // Check that the field is using the expected string value.
     $this->assertIdentical('1', $data['display']['default']['display_options']['filters']['status']['value']);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:12,代码来源:BooleanFilterValuesUpdateTest.php

示例6: createView

 /**
  * {@inheritdoc}
  */
 public function createView($options = NULL)
 {
     if ($view_template = $this->loadTemplate($options)) {
         $view_template['id'] = $options['id'];
         $view_template['label'] = $options['label'];
         $view_template['description'] = $options['description'];
         return View::create($view_template);
     }
     return NULL;
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:13,代码来源:ViewsDuplicateBuilderBase.php

示例7: doViewTest

 /**
  * Tests XSS coming from View block labels.
  */
 protected function doViewTest()
 {
     $view = View::create(['id' => $this->randomMachineName(), 'label' => '<script>alert("view");</script>']);
     $view->addDisplay('block');
     $view->save();
     $this->drupalGet(Url::fromRoute('block.admin_display'));
     $this->clickLink('<script>alert("view");</script>');
     $this->assertRaw('&lt;script&gt;alert(&quot;view&quot;);&lt;/script&gt;');
     $this->assertNoRaw('<script>alert("view");</script>');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:13,代码来源:BlockXssTest.php

示例8: doViewTest

 /**
  * Tests XSS coming from View block labels.
  */
 protected function doViewTest()
 {
     $view = View::create(['id' => $this->randomMachineName(), 'label' => '<script>alert("view");</script>']);
     $view->addDisplay('block');
     $view->save();
     $this->drupalGet(Url::fromRoute('block.admin_display'));
     $this->clickLinkPartialName('Place block');
     // The block admin label is automatically XSS admin filtered.
     $this->assertRaw('alert("view");');
     $this->assertNoRaw('<script>alert("view");</script>');
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:14,代码来源:BlockXssTest.php

示例9: testViewsUpdate8004

 /**
  * Tests that field handlers are updated properly.
  */
 public function testViewsUpdate8004()
 {
     $this->runUpdates();
     // Load and initialize our test view.
     $view = View::load('test_duplicate_field_handlers');
     $data = $view->toArray();
     // Check that the field is using the expected base table.
     $this->assertEqual('node_field_data', $data['display']['default']['display_options']['fields']['nid']['table']);
     $this->assertEqual('node_field_data', $data['display']['default']['display_options']['filters']['type']['table']);
     $this->assertEqual('node_field_data', $data['display']['default']['display_options']['sorts']['vid']['table']);
     $this->assertEqual('node_field_data', $data['display']['default']['display_options']['arguments']['nid']['table']);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:15,代码来源:FieldHandlersUpdateTest.php

示例10: testHandlers

 /**
  * Tests most of the handlers.
  */
 public function testHandlers()
 {
     $this->drupalCreateContentType(array('type' => 'article'));
     $this->addDefaultCommentField('node', 'article');
     $object_types = array_keys(ViewExecutable::getHandlerTypes());
     foreach ($this->container->get('views.views_data')->get() as $base_table => $info) {
         if (!isset($info['table']['base'])) {
             continue;
         }
         $view = View::create(array('base_table' => $base_table));
         $view = $view->getExecutable();
         // @todo The groupwise relationship is currently broken.
         $exclude[] = 'taxonomy_term_field_data:tid_representative';
         $exclude[] = 'users_field_data:uid_representative';
         // Go through all fields and there through all handler types.
         foreach ($info as $field => $field_info) {
             // Table is a reserved key for the metainformation.
             if ($field != 'table' && !in_array("{$base_table}:{$field}", $exclude)) {
                 $item = array('table' => $base_table, 'field' => $field);
                 foreach ($object_types as $type) {
                     if (isset($field_info[$type]['id'])) {
                         $options = array();
                         if ($type == 'filter') {
                             $handler = $this->container->get("plugin.manager.views.{$type}")->getHandler($item);
                             // Set the value to use for the filter based on the filter type.
                             if ($handler instanceof InOperator) {
                                 $options['value'] = array(1);
                             } else {
                                 $options['value'] = 1;
                             }
                         }
                         $view->addHandler('default', $type, $base_table, $field, $options);
                     }
                 }
             }
         }
         // Go through each step individually to see whether some parts are
         // failing.
         $view->build();
         $view->preExecute();
         $view->execute();
         $view->render();
         // Make sure all handlers extend the HandlerBase.
         foreach ($object_types as $type) {
             if (isset($view->{$type})) {
                 foreach ($view->{$type} as $handler) {
                     $this->assertTrue($handler instanceof HandlerBase, format_string('@type handler of class %class is an instance of HandlerBase', array('@type' => $type, '%class' => get_class($handler))));
                 }
             }
         }
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:55,代码来源:HandlerAllTest.php

示例11: testTitleText

 /**
  * Tests the title area handler.
  */
 public function testTitleText()
 {
     $this->drupalGet('test-area-title');
     $this->assertTitle('test_title_header | Drupal');
     // Check the view to return no result.
     /** @var \Drupal\views\Entity\View $view */
     $view = View::load('test_area_title');
     $display =& $view->getDisplay('default');
     $display['display_options']['filters']['id'] = ['field' => 'id', 'id' => 'id', 'table' => 'views_test_data', 'relationship' => 'none', 'plugin_id' => 'numeric', 'provider' => 'views_test_data', 'value' => ['value' => '042118160112']];
     $view->save();
     $this->drupalGet('test-area-title');
     $this->assertTitle('test_title_empty | Drupal');
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:16,代码来源:AreaTitleWebTest.php

示例12: testFeedPage

 /**
  * Creates a feed and checks that feed's page.
  */
 public function testFeedPage()
 {
     // Increase the number of items published in the rss.xml feed so we have
     // enough articles to test paging.
     $view = View::load('frontpage');
     $display =& $view->getDisplay('feed_1');
     $display['display_options']['pager']['options']['items_per_page'] = 30;
     $view->save();
     // Create a feed with 30 items.
     $this->createSampleNodes(30);
     $feed = $this->createFeed();
     $this->updateFeedItems($feed, 30);
     // Check for presence of an aggregator pager.
     $this->drupalGet('aggregator');
     $elements = $this->xpath("//ul[contains(@class, :class)]", array(':class' => 'pager__items'));
     $this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
     // Check for sources page title.
     $this->drupalGet('aggregator/sources');
     $titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => 'Sources'));
     $this->assertTrue(!empty($titles), 'Source page contains correct title.');
     // Find the expected read_more link on the sources page.
     $href = $feed->url();
     $links = $this->xpath('//a[@href = :href]', array(':href' => $href));
     $this->assertTrue(isset($links[0]), SafeMarkup::format('Link to href %href found.', array('%href' => $href)));
     $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $cache_tags = explode(' ', $cache_tags_header);
     $this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
     // Check the rss aggregator page as anonymous user.
     $this->drupalLogout();
     $this->drupalGet('aggregator/rss');
     $this->assertResponse(403);
     // Check the rss aggregator page as admin.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('aggregator/rss');
     $this->assertResponse(200);
     $this->assertEqual($this->drupalGetHeader('Content-type'), 'application/rss+xml; charset=utf-8');
     // Check the opml aggregator page.
     $this->drupalGet('aggregator/opml');
     $outline = $this->xpath('//outline[1]');
     $this->assertEqual($outline[0]['type'], 'rss', 'The correct type attribute is used for rss OPML.');
     $this->assertEqual($outline[0]['text'], $feed->label(), 'The correct text attribute is used for rss OPML.');
     $this->assertEqual($outline[0]['xmlurl'], $feed->getUrl(), 'The correct xmlUrl attribute is used for rss OPML.');
     // Check for the presence of a pager.
     $this->drupalGet('aggregator/sources/' . $feed->id());
     $elements = $this->xpath("//ul[contains(@class, :class)]", array(':class' => 'pager__items'));
     $this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
     $cache_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
     $this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
     $this->assertTrue(in_array('aggregator_feed_view', $cache_tags));
     $this->assertTrue(in_array('aggregator_item_view', $cache_tags));
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:54,代码来源:AggregatorRenderingTest.php

示例13: testPostUpdateFunction

 /**
  * Tests post update function fixes dependencies.
  *
  * @see views_post_update_taxonomy_index_tid()
  */
 public function testPostUpdateFunction()
 {
     /** @var \Drupal\views\Entity\View $view */
     $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
     // Dependencies are sorted.
     $content_dependencies = [$this->terms[3]->getConfigDependencyName(), $this->terms[4]->getConfigDependencyName()];
     sort($content_dependencies);
     $this->assertEqual(['config' => ['taxonomy.vocabulary.tags'], 'content' => $content_dependencies, 'module' => ['node', 'taxonomy', 'user']], $view->calculateDependencies()->getDependencies());
     $this->terms[3]->delete();
     \Drupal::moduleHandler()->loadInclude('views', 'post_update.php');
     views_post_update_taxonomy_index_tid();
     $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
     $this->assertEqual(['config' => ['taxonomy.vocabulary.tags'], 'content' => [$this->terms[4]->getConfigDependencyName()], 'module' => ['node', 'taxonomy', 'user']], $view->getDependencies());
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:TaxonomyIndexTidFilterTest.php

示例14: testUpdateImageStyleDependencies

 /**
  * Tests the updating of views dependencies to image styles.
  */
 public function testUpdateImageStyleDependencies()
 {
     $config_dependencies = View::load('foo')->getDependencies()['config'];
     // Checks that 'thumbnail' image style is not a dependency of view 'foo'.
     $this->assertFalse(in_array('image.style.thumbnail', $config_dependencies));
     // We test the case the the field formatter image style doesn't exist.
     // Checks that 'nonexistent' image style is not a dependency of view 'foo'.
     $this->assertFalse(in_array('image.style.nonexistent', $config_dependencies));
     // Run updates.
     $this->runUpdates();
     $config_dependencies = View::load('foo')->getDependencies()['config'];
     // Checks that 'thumbnail' image style is a dependency of view 'foo'.
     $this->assertTrue(in_array('image.style.thumbnail', $config_dependencies));
     // The 'nonexistent' style doesn't exist, thus is not a dependency. Checks
     // that 'nonexistent' image style is a not dependency of view 'foo'.
     $this->assertFalse(in_array('image.style.nonexistent', $config_dependencies));
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:20,代码来源:ImageStyleDependencyUpdateTest.php

示例15: testQueryUI

 /**
  * Tests query plugins settings.
  */
 public function testQueryUI()
 {
     $view = View::load('test_view');
     $display =& $view->getDisplay('default');
     $display['display_options']['query'] = ['type' => 'query_test'];
     $view->save();
     // Save some query settings.
     $query_settings_path = "admin/structure/views/nojs/display/test_view/default/query";
     $random_value = $this->randomMachineName();
     $this->drupalPostForm($query_settings_path, array('query[options][test_setting]' => $random_value), t('Apply'));
     $this->drupalPostForm(NULL, array(), t('Save'));
     // Check that the settings are saved into the view itself.
     $view = Views::getView('test_view');
     $view->initDisplay();
     $view->initQuery();
     $this->assertEqual($random_value, $view->query->options['test_setting'], 'Query settings got saved');
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:20,代码来源:QueryTest.php


注:本文中的Drupal\views\Entity\View类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。