當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。