From d95edd80fbc12c0bfd8cb6491372b2679b481ff8 Mon Sep 17 00:00:00 2001
From: Chaitanya Anil Kulkarni <chaitanyakul@cybage.com>
Date: Jul 27, 2017 8:08:40 PM

QueryFactory is deprecated

diff --git a/config_entity_example/src/Form/RobotFormBase.php b/config_entity_example/src/Form/RobotFormBase.php
index c1cead1..78dc7c6 100644
--- a/config_entity_example/src/Form/RobotFormBase.php
+++ b/config_entity_example/src/Form/RobotFormBase.php
@@ -3,7 +3,7 @@
 namespace Drupal\config_entity_example\Form;
 
 use Drupal\Core\Entity\EntityForm;
-use Drupal\Core\Entity\Query\QueryFactory;
+use Drupal\Core\Entity\EntityTypeManager;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Link;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -21,9 +21,9 @@
 class RobotFormBase extends EntityForm {
 
   /**
-   * @var \Drupal\Core\Entity\Query\QueryFactory
+   * @var \Drupal\Core\Entity\EntityTypeManager
    */
-  protected $entityQueryFactory;
+  protected $entityTypeManager;
 
   /**
    * Construct the RobotFormBase.
@@ -33,11 +33,11 @@
    * from the container. We later use this query factory to build an entity
    * query for the exists() method.
    *
-   * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
+   * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
    *   An entity query factory for the robot entity type.
    */
-  public function __construct(QueryFactory $query_factory) {
-    $this->entityQueryFactory = $query_factory;
+  public function __construct(EntityTypeManager $entity_type_manager) {
+    $this->entityTypeManager  = $entity_type_manager;
   }
 
   /**
@@ -55,7 +55,7 @@
    * pass the factory to our class as a constructor parameter.
    */
   public static function create(ContainerInterface $container) {
-    return new static($container->get('entity.query'));
+    return new static($container->get('entity_type.manager'));
   }
 
   /**
@@ -126,7 +126,7 @@
    */
   public function exists($entity_id, array $element, FormStateInterface $form_state) {
     // Use the query factory to build a new robot entity query.
-    $query = $this->entityQueryFactory->get('robot');
+    $query = $this->entityTypeManager->getStorage('robot')->getQuery();
 
     // Query the entity ID to see if its in use.
     $result = $query->condition('id', $element['#field_prefix'] . $entity_id)
