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


PHP Drupal::entityQueryAggregate方法代码示例

本文整理汇总了PHP中Drupal::entityQueryAggregate方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::entityQueryAggregate方法的具体用法?PHP Drupal::entityQueryAggregate怎么用?PHP Drupal::entityQueryAggregate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal的用法示例。


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

示例1: testEntityQuery

 /**
  * Tests using entity query with ContentEntityNullStorage.
  *
  * @see \Drupal\Core\Entity\Query\Null\Query
  */
 public function testEntityQuery()
 {
     $this->assertIdentical(0, \Drupal::entityQuery('contact_message')->count()->execute(), 'Counting a null storage returns 0.');
     $this->assertIdentical([], \Drupal::entityQuery('contact_message')->execute(), 'Querying a null storage returns an empty array.');
     $this->assertIdentical([], \Drupal::entityQuery('contact_message')->condition('contact_form', 'test')->execute(), 'Querying a null storage returns an empty array and conditions are ignored.');
     $this->assertIdentical([], \Drupal::entityQueryAggregate('contact_message')->aggregate('name', 'AVG')->execute(), 'Aggregate querying a null storage returns an empty array');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:12,代码来源:ContentEntityNullStorageTest.php

示例2: testSnippets


//.........这里部分代码省略.........
     $state->delete('mymodule.my_state_variable_name');
     $new_value = $state->get('mymodule.my_state_variable_name');
     $this->assertNull($new_value, 'After delete, could not retrieve state value');
     // Snippets from "Internationalizing User Interface Text" section in
     // chapter 2. Good code only; bad code examples are omitted.
     $button_text = t('Save');
     $this->assertEqual($button_text, 'Save', 't() worked OK on simple string');
     $user_name = 'foo';
     $message_string = t('Hello @user_name', array('@user_name' => $user_name));
     $this->outputHTML($message_string, 't() with variables output');
     $this->assertEqual($message_string, 'Hello foo', 't() worked OK on string with variable');
     $test = (object) array();
     $foo = $test instanceof MyClass;
     // Database snippets from "Querying the Database with the Database API"
     // section in Chapter 2.
     // Make a blocked user for querying purposes.
     $account = $this->drupalCreateUser(array());
     $account->status = 0;
     $account->save();
     // Query by status 0 (blocked).
     $desired_status = 0;
     $found = FALSE;
     $result = db_query('SELECT * FROM {users_field_data} u WHERE u.status = :status', array(':status' => $desired_status));
     foreach ($result as $record) {
         $this->outputVariable($record, 'User database record');
         if ($record->uid == $account->id()) {
             $found = TRUE;
         }
     }
     $this->assertTrue($found, 'Created user was found by status query');
     // Test the ability to query by user name.
     $found = FALSE;
     $result = db_query('SELECT * FROM {users_field_data} u WHERE u.name = :name', array(':name' => $account->getUsername()));
     foreach ($result as $record) {
         if ($record->uid == $account->id()) {
             $found = TRUE;
         }
     }
     $this->assertTrue($found, 'Created user was found by name query');
     // Create a node, for query purposes.
     $newnode = $this->drupalCreateNode();
     // Log in as user who can access content.
     $account = $this->drupalCreateUser(array('access content'));
     $this->drupalLogin($account);
     $query = db_select('node', 'n');
     $query->innerJoin('node_field_data', 'nd', 'n.nid = nd.nid AND n.vid = nd.vid');
     $query->innerJoin('users_field_data', 'u', 'u.uid = nd.uid');
     $query->addField('nd', 'changed', 'last_updated');
     $query->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->limit(20)->fields('nd', array('title', 'nid'))->fields('u', array('name'))->addTag('node_access')->condition('nd.status', 1);
     $result = $query->execute();
     $found = FALSE;
     foreach ($result as $node) {
         $title = $node->title;
         if ($node->nid == $newnode->id()) {
             $found = TRUE;
             $this->verbose("Found node with title {$title}");
         }
     }
     $this->assertTrue($found, "Found node in query");
     // Snippets from the "Cleansing and Checking User-Provided Input"
     // section in Chapter 2. Only "good" code is included.
     $text = '<h2>Text with HTML</h2>';
     $plain_text = htmlentities($text);
     $url = 'http://example.com';
     $url_object = Url::fromUri($url);
     $output = Drupal::l($text, $url_object);
     $this->outputHTML($output, 'l() output');
     $this->assertEqual($output, '<a href="' . $url . '">' . $plain_text . '</a>', 'l output is as expected');
     // Form builder snippet from "Basic Form Generation and Processing in
     // Drupal 8", chapter 4.
     $my_render_array['personal_data_form'] = \Drupal::formBuilder()->getForm('Drupal\\mymodule\\Form\\PersonalDataForm');
     $this->outputVariable($my_render_array, 'Personal data form array');
     $this->assertTrue(isset($my_render_array['personal_data_form']['first_name']), 'First name field is present in form array');
     $builder = $container->get('form_builder');
     $my_render_array['personal_data_form'] = $builder->getForm('Drupal\\mymodule\\Form\\PersonalDataForm');
     $this->assertTrue(isset($my_render_array['personal_data_form']['first_name']), 'First name field is present in form array');
     // Entity query snippets from "Querying and Loading Entities in Drupal 8",
     // chapter 4.
     // Try various methods for retrieving the query.
     $query = \Drupal::entityQuery('node');
     $this->assertTrue($query, 'Query is not null');
     $query = \Drupal::entityQueryAggregate('node');
     $this->assertTrue($query, 'Query is not null');
     $query_service = $container->get('entity.query');
     $query = $query_service->getAggregate('node');
     $this->assertTrue($query, 'Query is not null');
     // Try an actual query.
     $query = $query_service->get('node');
     $query->condition('type', $newnode->getType());
     $ids = $query->execute();
     // Try different methods of getting storage manager.
     $storage = \Drupal::entityManager()->getStorage('node');
     $this->assertTrue($storage, 'Storage is not null');
     // Load the entities and verify.
     $storage = $container->get('entity.manager')->getStorage('node');
     $entities = $storage->loadMultiple($ids);
     $this->assertEqual(count($entities), 1, 'One node was found');
     $first = reset($entities);
     $this->assertEqual($first->getTitle(), $newnode->getTitle(), 'Correct node was found');
 }
开发者ID:Jamesadamar,项目名称:programmers_guide_to_drupal,代码行数:101,代码来源:MyModuleSnippetsTest.php

示例3: testEntityQueryAggregate

 /**
  * Tests the entityQueryAggregate() method.
  *
  * @covers ::entityQueryAggregate
  */
 public function testEntityQueryAggregate()
 {
     $query = $this->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryFactory')->disableOriginalConstructor()->getMock();
     $query->expects($this->once())->method('getAggregate')->with('test_entity', 'OR')->will($this->returnValue(TRUE));
     $this->setMockContainerService('entity.query', $query);
     $this->assertNotNull(\Drupal::entityQueryAggregate('test_entity', 'OR'));
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:12,代码来源:DrupalTest.php


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