3
3
namespace Drupal \config_entity_example \Form ;
4
4
5
5
use Drupal \Core \Entity \EntityForm ;
6
- use Drupal \Core \Entity \Query \ QueryFactory ;
6
+ use Drupal \Core \Entity \EntityStorageInterface ;
7
7
use Drupal \Core \Form \FormStateInterface ;
8
8
use Drupal \Core \Link ;
9
9
use Symfony \Component \DependencyInjection \ContainerInterface ;
21
21
class RobotFormBase extends EntityForm {
22
22
23
23
/**
24
- * @var \Drupal\Core\Entity\Query\QueryFactory
24
+ * @var \Drupal\Core\Entity\EntityStorageInterface
25
25
*/
26
- protected $ entityQueryFactory ;
26
+ protected $ entityStorage ;
27
27
28
28
/**
29
29
* Construct the RobotFormBase.
@@ -33,11 +33,11 @@ class RobotFormBase extends EntityForm {
33
33
* from the container. We later use this query factory to build an entity
34
34
* query for the exists() method.
35
35
*
36
- * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
36
+ * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
37
37
* An entity query factory for the robot entity type.
38
38
*/
39
- public function __construct (QueryFactory $ query_factory ) {
40
- $ this ->entityQueryFactory = $ query_factory ;
39
+ public function __construct (EntityStorageInterface $ entity_storage ) {
40
+ $ this ->entityStorage = $ entity_storage ;
41
41
}
42
42
43
43
/**
@@ -55,7 +55,7 @@ public function __construct(QueryFactory $query_factory) {
55
55
* pass the factory to our class as a constructor parameter.
56
56
*/
57
57
public static function create (ContainerInterface $ container ) {
58
- return new static ($ container ->get ('entity.query ' ));
58
+ return new static ($ container ->get ('entity_type.manager ' )-> getStorage ( ' robot ' ));
59
59
}
60
60
61
61
/**
@@ -126,7 +126,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
126
126
*/
127
127
public function exists ($ entity_id , array $ element , FormStateInterface $ form_state ) {
128
128
// Use the query factory to build a new robot entity query.
129
- $ query = $ this ->entityQueryFactory -> get ( ' robot ' );
129
+ $ query = $ this ->entityStorage -> getQuery ( );
130
130
131
131
// Query the entity ID to see if its in use.
132
132
$ result = $ query ->condition ('id ' , $ element ['#field_prefix ' ] . $ entity_id )
0 commit comments