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


PHP Query\QueryFactory类代码示例

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


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

示例1: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->entityQuery = $this->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryInterface')->disableOriginalConstructor()->getMock();
     $this->entityQueryFactory = $this->getMockBuilder('Drupal\\Core\\Entity\\Query\\QueryFactory')->disableOriginalConstructor()->getMock();
     $this->entityQueryFactory->expects($this->any())->method('get')->will($this->returnValue($this->entityQuery));
     parent::setUp();
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:10,代码来源:DedupeEntityTest.php

示例2: __construct

 /**
  * Generates IVW tracking information.
  *
  * @param EntityManagerInterface $entity_manager
  *   The entity query object for taxonomy terms.
  * @param QueryFactory $query
  *   The entity query object for taxonomy terms.
  * @param ConfigFactoryInterface $config_factory
  *   The config factory service.
  * @param PathMatcher $path_match
  *   The current path match.
  * @param CurrentRouteMatch $current_route_match
  *   The current route match.
  * @param Token $token
  *   Token service.
  */
 public function __construct(EntityManagerInterface $entity_manager, QueryFactory $query, ConfigFactoryInterface $config_factory, PathMatcher $path_match, CurrentRouteMatch $current_route_match, Token $token)
 {
     $this->termStorage = $entity_manager->getStorage('taxonomy_term');
     $this->nodeQuery = $query->get('node');
     $this->configFactory = $config_factory;
     $this->pathMatch = $path_match;
     $this->currentRouteMatch = $current_route_match;
     $this->token = $token;
 }
开发者ID:Cyberschorsch,项目名称:module-ivw_integration,代码行数:25,代码来源:BddIvwTracker.php

示例3: exists

 /**
  * Checks for an existing ECK entity type.
  *
  * @param string|int $entity_id
  *   The entity ID.
  * @param array $element
  *   The form element.
  * @param FormStateInterface $form_state
  *   The form state.
  *
  * @return bool
  *   TRUE if this format already exists, FALSE otherwise.
  */
 public function exists($entity_id, array $element, FormStateInterface $form_state)
 {
     // Use the query factory to build a new event entity query.
     $query = $this->entityQueryFactory->get('eck_entity_type');
     // Query the entity ID to see if its in use.
     $result = $query->condition('id', $element['#field_prefix'] . $entity_id)->execute();
     // We don't need to return the ID, only if it exists or not.
     return (bool) $result;
 }
开发者ID:jokas,项目名称:d8.dev,代码行数:22,代码来源:EckEntityTypeFormBase.php

示例4: __construct

 /**
  * Constructor.
  *
  * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
  *   The entity field manager.
  * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
  *   The event displatcher.
  * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
  *   The entity query factory.
  * @param \Drupal\Core\Database\Connection $connection
  *   The database connection.
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
  *   The config factory to get flippy settings.
  * @param \Drupal\Core\Utility\Token
  *   Drupal token service.
  * @param \Drupal\Core\Language\LanguageManager
  *   Drupal Language manager service.
  */
 public function __construct(EntityFieldManagerInterface $entityFieldManager, EventDispatcherInterface $event_dispatcher, QueryFactory $query_factory, Connection $connection, ConfigFactoryInterface $config_factory, Token $token, LanguageManager $languageManager)
 {
     $this->entityFieldManager = $entityFieldManager;
     $this->eventDispatcher = $event_dispatcher;
     $this->nodeQuery = $query_factory->get('node');
     $this->connection = $connection;
     $this->flippySettings = $config_factory->get('flippy.settings');
     $this->token = $token;
     $this->languageManager = $languageManager;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:28,代码来源:FlippyPager.php

示例5: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $items = array();
     // When on a node page, the parameter is already upcast as a node.
     $node = \Drupal::routeMatch()->getParameter('node');
     if ($node) {
         // Read about entity query at http://www.sitepoint.com/drupal-8-version-entityfieldquery/.
         // See query API at https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Query%21QueryInterface.php/interface/QueryInterface/8.
         // The static method for using the query service would have been:
         // $query = \Drupal::entityQuery('node');
         // Use injected queryFactory to look for items that are related
         // to the show that matches the input nid.
         $query = $this->entity_query->get('node')->condition('status', 1)->condition('type', 'tv_episode')->sort('field_related_season.entity.field_season_number.value', 'DESC')->sort('field_episode_number', 'DESC')->range(0, 5)->condition('field_related_season.entity.field_related_show.entity.nid', $node->id());
         $nids = $query->execute();
         // Note that entity_load() is deprecated.
         // The static method of loading the entity would have been:
         // \Drupal\node\Entity\Node::load();
         // Use the injected entityManager to load the results into an array of node objects.
         $nodes = $this->entity_manager->getStorage('node')->loadMultiple($nids);
         foreach ($nodes as $node) {
             // Create a render array for each title field.
             // Note that field_view_field() is deprecated, use the view method on the field.
             $title = $node->title->view('full');
             // Entities have a handy toLink() method.
             $items[] = $node->toLink($title);
         }
     }
     // Return a render array for a html list.
     return ['#theme' => 'item_list', '#items' => $items, '#cache' => ['contexts' => ['route']]];
 }
开发者ID:Lullabot,项目名称:challenge4,代码行数:33,代码来源:DemoBlock.php

示例6: helloWorld

 /**
  * Say hello to the world.
  *
  * @return string
  *   Return "Hello world!" string.
  */
 public function helloWorld(EntityViewModeInterface $viewmode)
 {
     $content = ['#type' => 'markup', '#markup' => $this->t('Hello world!')];
     // Second version displaying the opening hours of the library.
     $opening_hours = $this->config('happy_alexandrie.library_config')->get('opening_hours');
     if (!empty($opening_hours)) {
         $content = ['#markup' => $this->t('<p>Greetings dear adventurer!</p><p>Opening hours:<br />@opening_hours</p>', array('@opening_hours' => $opening_hours))];
     }
     // Third version with the query
     // Query against our entities.
     $query = $this->query_factory->get('node')->condition('status', 1)->condition('type', 'alexandrie_book')->condition('changed', REQUEST_TIME, '<')->range(0, 5);
     $nids = $query->execute();
     if ($nids) {
         // Load the storage manager of our entity.
         $storage = $this->entity_manager->getStorage('node');
         // Now we can load the entities.
         $nodes = $storage->loadMultiple($nids);
         list($entity_type, $viewmode_name) = explode('.', $viewmode->getOriginalId());
         // Get the EntityViewBuilder instance.
         $render_controller = $this->entity_manager->getViewBuilder('node');
         $build = $render_controller->viewMultiple($nodes, $viewmode_name);
         $build['#markup'] = $this->t('Happy Query by view mode: @label', array('@label' => $viewmode->label()));
         $content[] = $build;
     } else {
         $content[] = array('#markup' => $this->t('No result'));
     }
     return $content;
 }
开发者ID:Happyculture,项目名称:exercices,代码行数:34,代码来源:AlexandrieController.php

示例7: interact

 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $viewId = $input->getArgument('view-id');
     if (!$viewId) {
         $views = $this->entityQuery->get('view')->condition('status', 1)->execute();
         $viewId = $io->choiceNoList($this->trans('commands.views.debug.arguments.view-id'), $views);
         $input->setArgument('view-id', $viewId);
     }
 }
开发者ID:ddrozdik,项目名称:DrupalConsole,代码行数:13,代码来源:DisableCommand.php

示例8: load

 /**
  * {@inheritdoc}
  */
 public function load()
 {
     $entity_query = $this->queryFactory->get('user');
     $entity_query->condition('uid', 0, '<>');
     $entity_query->pager(50);
     $header = $this->buildHeader();
     $entity_query->tableSort($header);
     $uids = $entity_query->execute();
     return $this->storage->loadMultiple($uids);
 }
开发者ID:shumer,项目名称:blog,代码行数:13,代码来源:UserListBuilder.php

示例9: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $blocks = $this->queryFactory->get('block_content')->condition('type', $this->entity->id())->execute();
     if (!empty($blocks)) {
         $caption = '<p>' . format_plural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '</p>';
         $form['description'] = array('#markup' => $caption);
         return $form;
     } else {
         return parent::buildForm($form, $form_state);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:BlockContentTypeDeleteForm.php

示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $num_nodes = $this->queryFactory->get('node')->condition('type', $this->entity->id())->count()->execute();
     if ($num_nodes) {
         $caption = '<p>' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $this->entity->label())) . '</p>';
         $form['#title'] = $this->getQuestion();
         $form['description'] = array('#markup' => $caption);
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:NodeTypeDeleteConfirm.php

示例11: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $product_count = $this->queryFactory->get('commerce_product')->condition('type', $this->entity->id())->count()->execute();
     if ($product_count) {
         $caption = '<p>' . $this->formatPlural($product_count, '%type is used by 1 product on your site. You can not remove this product type until you have removed all of the %type products.', '%type is used by @count products on your site. You may not remove %type until you have removed all of the %type products.', ['%type' => $this->entity->label()]) . '</p>';
         $form['#title'] = $this->getQuestion();
         $form['description'] = ['#markup' => $caption];
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:marmouset,项目名称:drupal,代码行数:14,代码来源:ProductTypeDeleteForm.php

示例12: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $num_profiles = $this->queryFactory->get('profile')->condition('type', $this->entity->id())->count()->execute();
     if ($num_profiles) {
         $caption = '<p>' . \Drupal::translation()->formatPlural($num_profiles, '%type is used by 1 profile on your site. You can not remove this profile type until you have removed all of the %type profiles.', '%type is used by @count profiles on your site. You may not remove %type until you have removed all of the %type profiles.', ['%type' => $this->entity->label()]) . '</p>';
         $form['#title'] = $this->entity->label();
         $form['description'] = ['#markup' => $caption];
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:14,代码来源:ProfileTypeDeleteForm.php

示例13: titleQuery

 /**
  * Override the behavior of titleQuery(). Get the filenames.
  */
 public function titleQuery()
 {
     $fids = $this->entityQuery->get('file')->condition('fid', $this->value, 'IN')->execute();
     $controller = $this->entityManager->getStorage('file');
     $files = $controller->loadMultiple($fids);
     $titles = array();
     foreach ($files as $file) {
         $titles[] = $file->getFilename();
     }
     return $titles;
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:14,代码来源:Fid.php

示例14: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $num_support_tickets = $this->queryFactory->get('support_ticket')->condition('support_ticket_type', $this->entity->id())->count()->execute();
     if ($num_support_tickets) {
         $caption = '<p>' . $this->formatPlural($num_support_tickets, '%type is used by 1 ticket on your site. You can not remove this support ticket type until you have removed all of the %type tickets.', '%type is used by @count tickets on your site. You may not remove %type until you have removed all of the %type tickets.', array('%type' => $this->entity->label())) . '</p>';
         $form['#title'] = $this->getQuestion();
         $form['description'] = array('#markup' => $caption);
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:14,代码来源:SupportTicketTypeDeleteConfirm.php

示例15: validatePath

 /**
  * {@inheritdoc}
  */
 public function validatePath(&$element, FormStateInterface $form_state)
 {
     // Ensure the path has a leading slash.
     $value = '/' . trim($element['#value'], '/');
     $form_state->setValueForElement($element, $value);
     // Ensure each path is unique.
     $path = $this->entityQuery->get('page')->condition('path', $value)->condition('id', $form_state->getValue('id'), '<>')->execute();
     if ($path) {
         $form_state->setErrorByName('path', $this->t('The page path must be unique.'));
     }
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:14,代码来源:PageFormBase.php


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