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


PHP QueryFactory::get方法代码示例

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


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

示例1: 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

示例2: 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

示例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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: buildForm

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

示例14: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Check if any entity of this type already exists.
     $content_number = $this->queryFactory->get($this->entity->getEntityType()->getBundleOf())->condition('type', $this->entity->id())->count()->execute();
     if (!empty($content_number)) {
         $warning_message = '<p>' . $this->formatPlural($content_number, '%type is used by 1 entity on your site. You can not remove this entity type until you have removed all of the %type entities.', '%type is used by @count entities on your site. You may not remove %type until you have removed all of the %type entities.', array('%type' => $this->entity->label())) . '</p>';
         $form['#title'] = $this->getQuestion();
         $form['description'] = array('#markup' => $warning_message);
         return $form;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:jokas,项目名称:d8.dev,代码行数:15,代码来源:EckEntityBundleDeleteConfirm.php

示例15: getDerivativeDefinitions

 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     // Get all custom menu links which should be rediscovered.
     $entity_ids = $this->queryFactory->get('menu_link_content')->condition('rediscover', TRUE)->execute();
     $plugin_definitions = [];
     $menu_link_content_entities = $this->entityManager->getStorage('menu_link_content')->loadMultiple($entity_ids);
     /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content */
     foreach ($menu_link_content_entities as $menu_link_content) {
         $plugin_definitions[$menu_link_content->uuid()] = $menu_link_content->getPluginDefinition();
     }
     return $plugin_definitions;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:15,代码来源:MenuLinkContentDeriver.php


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