EntityType.php 21.1 KB
Newer Older
1
2
3
4
<?php

namespace Drupal\Core\Entity;

5
use Drupal\Component\Plugin\Definition\PluginDefinition;
6
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
7
use Drupal\Core\Entity\Exception\EntityTypeIdLengthException;
8
use Drupal\Core\StringTranslation\StringTranslationTrait;
9
use Drupal\Core\StringTranslation\TranslatableMarkup;
10
11
12

/**
 * Provides an implementation of an entity type and its metadata.
13
14
 *
 * @ingroup entity_api
15
 */
16
class EntityType extends PluginDefinition implements EntityTypeInterface {
17

18
  use DependencySerializationTrait;
19
20
  use StringTranslationTrait;

21
22
23
24
25
  /**
   * Indicates whether entities should be statically cached.
   *
   * @var bool
   */
26
  protected $static_cache = TRUE;
27
28
29
30
31
32

  /**
   * Indicates whether the rendered output of entities should be cached.
   *
   * @var bool
   */
33
  protected $render_cache = TRUE;
34
35
36
37
38
39

  /**
   * Indicates if the persistent cache of field data should be used.
   *
   * @var bool
   */
40
  protected $persistent_cache = TRUE;
41
42
43
44
45
46

  /**
   * An array of entity keys.
   *
   * @var array
   */
47
  protected $entity_keys = [];
48
49
50
51
52
53
54
55

  /**
   * The unique identifier of this entity type.
   *
   * @var string
   */
  protected $id;

56
57
58
59
60
61
62
63
64
  /**
   * The name of the original entity type class.
   *
   * This is only set if the class name is changed.
   *
   * @var string
   */
  protected $originalClass;

65
  /**
66
   * An array of handlers.
67
68
69
   *
   * @var array
   */
70
  protected $handlers = [];
71
72
73
74
75
76
77
78
79
80
81

  /**
   * The name of the default administrative permission.
   *
   * @var string
   */
  protected $admin_permission;

  /**
   * The permission granularity level.
   *
82
   * The allowed values are respectively "entity_type" or "bundle".
83
   *
84
   * @var string
85
   */
86
  protected $permission_granularity = 'entity_type';
87
88
89
90
91
  /**
   * Link templates using the URI template syntax.
   *
   * @var array
   */
92
  protected $links = [];
93
94
95
96

  /**
   * The name of a callback that returns the label of the entity.
   *
97
98
   * @var callable|null
   *
99
100
   * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Override the
   *   EntityInterface::label() method instead for dynamic labels.
101
102
   *
   * @see \Drupal\Core\Entity\EntityInterface::label()
103
   */
104
  protected $label_callback = NULL;
105
106
107
108
109
110

  /**
   * The name of the entity type which provides bundles.
   *
   * @var string
   */
111
  protected $bundle_entity_type = NULL;
112
113
114
115

  /**
   * The name of the entity type for which bundles are provided.
   *
116
   * @var string|null
117
   */
118
  protected $bundle_of = NULL;
119
120
121
122

  /**
   * The human-readable name of the entity bundles, e.g. Vocabulary.
   *
123
   * @var string|null
124
   */
125
  protected $bundle_label = NULL;
126
127
128
129

  /**
   * The name of the entity type's base table.
   *
130
   * @var string|null
131
   */
132
  protected $base_table = NULL;
133
134
135
136

  /**
   * The name of the entity type's revision data table.
   *
137
   * @var string|null
138
   */
139
  protected $revision_data_table = NULL;
140
141
142
143

  /**
   * The name of the entity type's revision table.
   *
144
   * @var string|null
145
   */
146
  protected $revision_table = NULL;
147
148
149
150

  /**
   * The name of the entity type's data table.
   *
151
   * @var string|null
152
   */
153
  protected $data_table = NULL;
154

155
156
157
158
159
160
161
  /**
   * Indicates whether the entity data is internal.
   *
   * @var bool
   */
  protected $internal = FALSE;

162
163
164
165
166
167
168
  /**
   * Indicates whether entities of this type have multilingual support.
   *
   * @var bool
   */
  protected $translatable = FALSE;

169
170
171
172
173
174
175
  /**
   * Indicates whether the revision form fields should be added to the form.
   *
   * @var bool
   */
  protected $show_revision_ui = FALSE;

176
177
178
  /**
   * The human-readable name of the type.
   *
179
   * @var string|\Drupal\Core\StringTranslation\TranslatableMarkup
180
181
   *
   * @see \Drupal\Core\Entity\EntityTypeInterface::getLabel()
182
   */
183
  protected $label = '';
184

185
186
187
  /**
   * The human-readable label for a collection of entities of the type.
   *
188
   * @var string|\Drupal\Core\StringTranslation\TranslatableMarkup
189
190
   *
   * @see \Drupal\Core\Entity\EntityTypeInterface::getCollectionLabel()
191
192
193
   */
  protected $label_collection = '';

194
195
196
  /**
   * The indefinite singular name of the type.
   *
197
   * @var string|\Drupal\Core\StringTranslation\TranslatableMarkup
198
199
   *
   * @see \Drupal\Core\Entity\EntityTypeInterface::getSingularLabel()
200
201
202
203
204
205
   */
  protected $label_singular = '';

  /**
   * The indefinite plural name of the type.
   *
206
   * @var string|\Drupal\Core\StringTranslation\TranslatableMarkup
207
208
   *
   * @see \Drupal\Core\Entity\EntityTypeInterface::getPluralLabel()
209
210
211
212
213
214
215
216
   */
  protected $label_plural = '';

  /**
   * A definite singular/plural name of the type.
   *
   * Needed keys: "singular" and "plural".
   *
217
   * @var string|\Drupal\Core\StringTranslation\TranslatableMarkup
218
219
   *
   * @see \Drupal\Core\Entity\EntityTypeInterface::getCountLabel()
220
221
222
   */
  protected $label_count = [];

223
224
225
  /**
   * A callable that can be used to provide the entity URI.
   *
226
   * @var callable|null
227
   */
228
  protected $uri_callback = NULL;
229

230
231
  /**
   * The machine name of the entity type group.
232
233
   *
   * @var string
234
235
236
237
238
   */
  protected $group;

  /**
   * The human-readable name of the entity type group.
239
240
241
242
   *
   * @var string|\Drupal\Core\StringTranslation\TranslatableMarkup
   *
   * @see \Drupal\Core\Entity\EntityTypeInterface::getGroupLabel()
243
244
245
   */
  protected $group_label;

246
247
248
249
250
251
252
  /**
   * The route name used by field UI to attach its management pages.
   *
   * @var string
   */
  protected $field_ui_base_route;

253
254
255
256
257
258
259
260
261
262
  /**
   * Indicates whether this entity type is commonly used as a reference target.
   *
   * This is used by the Entity reference field to promote an entity type in the
   * add new field select list in Field UI.
   *
   * @var bool
   */
  protected $common_reference_target = FALSE;

263
264
265
266
267
268
269
  /**
   * The list cache contexts for this entity type.
   *
   * @var string[]
   */
  protected $list_cache_contexts = [];

270
271
272
  /**
   * The list cache tags for this entity type.
   *
273
   * @var string[]
274
   */
275
  protected $list_cache_tags = [];
276

277
278
279
280
281
  /**
   * Entity constraint definitions.
   *
   * @var array[]
   */
282
  protected $constraints = [];
283

284
285
286
287
288
289
290
  /**
   * Any additional properties and values.
   *
   * @var array
   */
  protected $additional = [];

291
292
293
294
295
  /**
   * Constructs a new EntityType.
   *
   * @param array $definition
   *   An array of values from the annotation.
296
297
298
   *
   * @throws \Drupal\Core\Entity\Exception\EntityTypeIdLengthException
   *   Thrown when attempting to instantiate an entity type with too long ID.
299
300
   */
  public function __construct($definition) {
301
    // Throw an exception if the entity type ID is longer than 32 characters.
302
    if (mb_strlen($definition['id']) > static::ID_MAX_LENGTH) {
303
      throw new EntityTypeIdLengthException('Attempt to create an entity type with an ID longer than ' . static::ID_MAX_LENGTH . " characters: {$definition['id']}.");
304
305
    }

306
    foreach ($definition as $property => $value) {
307
      $this->set($property, $value);
308
    }
309
310

    // Ensure defaults.
311
    $this->entity_keys += [
312
      'revision' => '',
313
314
      'bundle' => '',
      'langcode' => '',
315
      'default_langcode' => 'default_langcode',
316
      'revision_translation_affected' => 'revision_translation_affected',
317
318
    ];
    $this->handlers += [
319
      'access' => 'Drupal\Core\Entity\EntityAccessControlHandler',
320
    ];
321
322
323
    if (isset($this->handlers['storage'])) {
      $this->checkStorageClass($this->handlers['storage']);
    }
324

325
326
    // Automatically add the "EntityChanged" constraint if the entity type
    // tracks the changed time.
327
    if ($this->entityClassImplements(EntityChangedInterface::class)) {
328
329
      $this->addConstraint('EntityChanged');
    }
330
331
332
333
334
    // Automatically add the "EntityUntranslatableFields" constraint if we have
    // an entity type supporting translatable fields and pending revisions.
    if ($this->entityClassImplements(ContentEntityInterface::class)) {
      $this->addConstraint('EntityUntranslatableFields');
    }
335

336
337
338
339
    // Ensure a default list cache tag is set.
    if (empty($this->list_cache_tags)) {
      $this->list_cache_tags = [$definition['id'] . '_list'];
    }
340
341
342
343
344
345
  }

  /**
   * {@inheritdoc}
   */
  public function get($property) {
346
347
348
349
350
351
352
    if (property_exists($this, $property)) {
      $value = isset($this->{$property}) ? $this->{$property} : NULL;
    }
    else {
      $value = isset($this->additional[$property]) ? $this->additional[$property] : NULL;
    }
    return $value;
353
354
355
356
357
358
  }

  /**
   * {@inheritdoc}
   */
  public function set($property, $value) {
359
360
361
362
363
364
    if (property_exists($this, $property)) {
      $this->{$property} = $value;
    }
    else {
      $this->additional[$property] = $value;
    }
365
366
367
    return $this;
  }

368
369
370
371
372
373
374
  /**
   * {@inheritdoc}
   */
  public function isInternal() {
    return $this->internal;
  }

375
376
377
378
  /**
   * {@inheritdoc}
   */
  public function isStaticallyCacheable() {
379
    return $this->static_cache;
380
381
382
383
384
385
  }

  /**
   * {@inheritdoc}
   */
  public function isRenderCacheable() {
386
    return $this->render_cache;
387
388
389
390
391
  }

  /**
   * {@inheritdoc}
   */
392
  public function isPersistentlyCacheable() {
393
    return $this->persistent_cache;
394
395
396
397
398
399
  }

  /**
   * {@inheritdoc}
   */
  public function getKeys() {
400
    return $this->entity_keys;
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
  }

  /**
   * {@inheritdoc}
   */
  public function getKey($key) {
    $keys = $this->getKeys();
    return isset($keys[$key]) ? $keys[$key] : FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function hasKey($key) {
    $keys = $this->getKeys();
    return !empty($keys[$key]);
  }

419
420
421
422
423
424
425
  /**
   * {@inheritdoc}
   */
  public function getOriginalClass() {
    return $this->originalClass ?: $this->class;
  }

426
427
428
429
  /**
   * {@inheritdoc}
   */
  public function setClass($class) {
430
431
432
433
434
    if (!$this->originalClass && $this->class) {
      // If the original class is currently not set, set it to the current
      // class, assume that is the original class name.
      $this->originalClass = $this->class;
    }
435
436

    return parent::setClass($class);
437
438
  }

439
440
441
442
443
444
445
  /**
   * {@inheritdoc}
   */
  public function entityClassImplements($interface) {
    return is_subclass_of($this->getClass(), $interface);
  }

446
447
448
449
  /**
   * {@inheritdoc}
   */
  public function isSubclassOf($class) {
450
    return $this->entityClassImplements($class);
451
452
453
454
455
  }

  /**
   * {@inheritdoc}
   */
456
457
  public function getHandlerClasses() {
    return $this->handlers;
458
459
460
461
462
  }

  /**
   * {@inheritdoc}
   */
463
464
465
466
  public function getHandlerClass($handler_type, $nested = FALSE) {
    if ($this->hasHandlerClass($handler_type, $nested)) {
      $handlers = $this->getHandlerClasses();
      return $nested ? $handlers[$handler_type][$nested] : $handlers[$handler_type];
467
    }
468
    return NULL;
469
470
471
472
473
  }

  /**
   * {@inheritdoc}
   */
474
475
  public function setHandlerClass($handler_type, $value) {
    $this->handlers[$handler_type] = $value;
476
477
478
479
480
481
    return $this;
  }

  /**
   * {@inheritdoc}
   */
482
483
484
  public function hasHandlerClass($handler_type, $nested = FALSE) {
    $handlers = $this->getHandlerClasses();
    if (!isset($handlers[$handler_type]) || ($nested && !isset($handlers[$handler_type][$nested]))) {
485
486
      return FALSE;
    }
487
    $handler = $handlers[$handler_type];
488
    if ($nested) {
489
      $handler = $handler[$nested];
490
    }
491
    return class_exists($handler);
492
493
494
495
496
497
  }

  /**
   * {@inheritdoc}
   */
  public function getStorageClass() {
498
    return $this->getHandlerClass('storage');
499
500
501
502
503
504
  }

  /**
   * {@inheritdoc}
   */
  public function setStorageClass($class) {
505
    $this->checkStorageClass($class);
506
    $this->handlers['storage'] = $class;
507
    return $this;
508
509
  }

510
  /**
511
   * Checks that the provided class is compatible with the current entity type.
512
513
514
515
516
517
518
519
   *
   * @param string $class
   *   The class to check.
   */
  protected function checkStorageClass($class) {
    // Nothing to check by default.
  }

520
521
522
523
  /**
   * {@inheritdoc}
   */
  public function getFormClass($operation) {
524
    return $this->getHandlerClass('form', $operation);
525
526
527
528
529
  }

  /**
   * {@inheritdoc}
   */
530
  public function setFormClass($operation, $class) {
531
    $this->handlers['form'][$operation] = $class;
532
533
534
535
536
537
    return $this;
  }

  /**
   * {@inheritdoc}
   */
538
  public function hasFormClasses() {
539
    return !empty($this->handlers['form']);
540
541
  }

542
543
544
545
546
547
548
  /**
   * {@inheritdoc}
   */
  public function hasRouteProviders() {
    return !empty($this->handlers['route_provider']);
  }

549
550
551
  /**
   * {@inheritdoc}
   */
552
  public function getListBuilderClass() {
553
    return $this->getHandlerClass('list_builder');
554
555
556
557
558
  }

  /**
   * {@inheritdoc}
   */
559
  public function setListBuilderClass($class) {
560
    $this->handlers['list_builder'] = $class;
561
562
563
    return $this;
  }

564
565
566
  /**
   * {@inheritdoc}
   */
567
  public function hasListBuilderClass() {
568
    return $this->hasHandlerClass('list_builder');
569
570
571
572
573
574
  }

  /**
   * {@inheritdoc}
   */
  public function getViewBuilderClass() {
575
    return $this->getHandlerClass('view_builder');
576
577
578
579
580
581
  }

  /**
   * {@inheritdoc}
   */
  public function setViewBuilderClass($class) {
582
    $this->handlers['view_builder'] = $class;
583
584
585
586
587
588
589
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function hasViewBuilderClass() {
590
    return $this->hasHandlerClass('view_builder');
591
592
  }

593
594
595
596
597
598
599
  /**
   * {@inheritdoc}
   */
  public function getRouteProviderClasses() {
    return !empty($this->handlers['route_provider']) ? $this->handlers['route_provider'] : [];
  }

600
601
602
  /**
   * {@inheritdoc}
   */
603
  public function getAccessControlClass() {
604
    return $this->getHandlerClass('access');
605
606
607
608
609
610
  }

  /**
   * {@inheritdoc}
   */
  public function setAccessClass($class) {
611
    $this->handlers['access'] = $class;
612
613
614
    return $this;
  }

615
616
617
618
619
620
621
622
623
624
625
  /**
   * {@inheritdoc}
   */
  public function getAdminPermission() {
    return $this->admin_permission ?: FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getPermissionGranularity() {
626
    return $this->permission_granularity;
627
628
629
630
631
632
  }

  /**
   * {@inheritdoc}
   */
  public function getLinkTemplates() {
633
    return $this->links;
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
  }

  /**
   * {@inheritdoc}
   */
  public function getLinkTemplate($key) {
    $links = $this->getLinkTemplates();
    return isset($links[$key]) ? $links[$key] : FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function hasLinkTemplate($key) {
    $links = $this->getLinkTemplates();
    return isset($links[$key]);
  }

  /**
   * {@inheritdoc}
   */
655
656
657
658
659
660
  public function setLinkTemplate($key, $path) {
    if ($path[0] !== '/') {
      throw new \InvalidArgumentException('Link templates accepts paths, which have to start with a leading slash.');
    }

    $this->links[$key] = $path;
661
662
663
664
665
666
667
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getLabelCallback() {
668
    @trigger_error('EntityType::getLabelCallback() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Override the EntityInterface::label() method instead for dynamic labels. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
669
    return $this->label_callback;
670
671
672
673
674
675
  }

  /**
   * {@inheritdoc}
   */
  public function setLabelCallback($callback) {
676
    @trigger_error('EntityType::setLabelCallback() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Override the EntityInterface::label() method instead for dynamic labels. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
677
678
679
680
681
682
683
684
    $this->label_callback = $callback;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function hasLabelCallback() {
685
    @trigger_error('EntityType::hasabelCallback() is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Override the EntityInterface::label() method instead for dynamic labels. See https://www.drupal.org/node/3050794', E_USER_DEPRECATED);
686
687
688
689
690
691
692
    return isset($this->label_callback);
  }

  /**
   * {@inheritdoc}
   */
  public function getBundleEntityType() {
693
    return $this->bundle_entity_type;
694
695
696
697
698
699
  }

  /**
   * {@inheritdoc}
   */
  public function getBundleOf() {
700
    return $this->bundle_of;
701
702
703
704
705
706
  }

  /**
   * {@inheritdoc}
   */
  public function getBundleLabel() {
707
708
709
710
711
712
713
714
715
    // If there is no bundle label defined, try to provide some sensible
    // fallbacks.
    if (!empty($this->bundle_label)) {
      return (string) $this->bundle_label;
    }
    elseif ($bundle_entity_type_id = $this->getBundleEntityType()) {
      return (string) \Drupal::entityTypeManager()->getDefinition($bundle_entity_type_id)->getLabel();
    }
    return (string) new TranslatableMarkup('@type_label bundle', ['@type_label' => $this->getLabel()], [], $this->getStringTranslation());
716
717
718
719
720
721
  }

  /**
   * {@inheritdoc}
   */
  public function getBaseTable() {
722
    return $this->base_table;
723
724
  }

725
726
727
728
729
730
731
  /**
   * {@inheritdoc}
   */
  public function showRevisionUi() {
    return $this->isRevisionable() && $this->show_revision_ui;
  }

732
733
734
735
736
737
738
  /**
   * {@inheritdoc}
   */
  public function isTranslatable() {
    return !empty($this->translatable);
  }

739
740
741
742
743
744
745
746
  /**
   * {@inheritdoc}
   */
  public function isRevisionable() {
    // Entity types are revisionable if a revision key has been specified.
    return $this->hasKey('revision');
  }

747
748
749
750
  /**
   * {@inheritdoc}
   */
  public function getRevisionDataTable() {
751
    return $this->revision_data_table;
752
753
754
755
756
757
  }

  /**
   * {@inheritdoc}
   */
  public function getRevisionTable() {
758
    return $this->revision_table;
759
760
761
762
763
764
  }

  /**
   * {@inheritdoc}
   */
  public function getDataTable() {
765
    return $this->data_table;
766
767
768
769
770
771
  }

  /**
   * {@inheritdoc}
   */
  public function getLabel() {
772
    return $this->label;
773
774
775
776
777
778
  }

  /**
   * {@inheritdoc}
   */
  public function getLowercaseLabel() {
779
    @trigger_error('EntityType::getLowercaseLabel() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Instead, you should call getSingularLabel(). See https://www.drupal.org/node/3075567', E_USER_DEPRECATED);
780
    return mb_strtolower($this->getLabel());
781
782
  }

783
784
785
786
787
788
789
790
791
792
793
  /**
   * {@inheritdoc}
   */
  public function getCollectionLabel() {
    if (empty($this->label_collection)) {
      $label = $this->getLabel();
      $this->label_collection = new TranslatableMarkup('@label entities', ['@label' => $label], [], $this->getStringTranslation());
    }
    return $this->label_collection;
  }

794
795
796
797
798
  /**
   * {@inheritdoc}
   */
  public function getSingularLabel() {
    if (empty($this->label_singular)) {
799
      $lowercase_label = mb_strtolower($this->getLabel());
800
801
802
803
804
805
806
807
808
809
      $this->label_singular = $lowercase_label;
    }
    return $this->label_singular;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluralLabel() {
    if (empty($this->label_plural)) {
810
      $lowercase_label = $this->getSingularLabel();
811
812
813
814
815
816
817
818
819
820
      $this->label_plural = new TranslatableMarkup('@label entities', ['@label' => $lowercase_label], [], $this->getStringTranslation());
    }
    return $this->label_plural;
  }

  /**
   * {@inheritdoc}
   */
  public function getCountLabel($count) {
    if (empty($this->label_count)) {
821
      return $this->formatPlural($count, '@count @label', '@count @label entities', ['@label' => $this->getSingularLabel()], ['context' => 'Entity type label']);
822
823
824
825
826
    }
    $context = isset($this->label_count['context']) ? $this->label_count['context'] : 'Entity type label';
    return $this->formatPlural($count, $this->label_count['singular'], $this->label_count['plural'], ['context' => $context]);
  }

827
828
829
830
  /**
   * {@inheritdoc}
   */
  public function getUriCallback() {
831
    return $this->uri_callback;
832
833
834
835
836
837
838
839
840
841
  }

  /**
   * {@inheritdoc}
   */
  public function setUriCallback($callback) {
    $this->uri_callback = $callback;
    return $this;
  }

842
843
844
845
846
847
848
849
850
851
852
  /**
   * {@inheritdoc}
   */
  public function getGroup() {
    return $this->group;
  }

  /**
   * {@inheritdoc}
   */
  public function getGroupLabel() {
853
    return !empty($this->group_label) ? $this->group_label : $this->t('Other', [], ['context' => 'Entity type group']);
854
855
  }

856
857
858
859
860
861
862
  /**
   * {@inheritdoc}
   */
  public function getListCacheContexts() {
    return $this->list_cache_contexts;
  }

863
864
865
866
867
868
869
  /**
   * {@inheritdoc}
   */
  public function getListCacheTags() {
    return $this->list_cache_tags;
  }

870
871
872
873
874
875
876
877
878
879
  /**
   * {@inheritdoc}
   */
  public function getConfigDependencyKey() {
    // Return 'content' for the default implementation as important distinction
    // is that dependencies on other configuration entities are hard
    // dependencies and have to exist before creating the dependent entity.
    return 'content';
  }

880
881
882
883
884
885
886
  /**
   * {@inheritdoc}
   */
  public function isCommonReferenceTarget() {
    return $this->common_reference_target;
  }

887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
  /**
   * {@inheritdoc}
   */
  public function getConstraints() {
    return $this->constraints;
  }

  /**
   * {@inheritdoc}
   */
  public function setConstraints(array $constraints) {
    $this->constraints = $constraints;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function addConstraint($constraint_name, $options = NULL) {
    $this->constraints[$constraint_name] = $options;
    return $this;
  }

910
911
912
913
914
915
916
  /**
   * {@inheritdoc}
   */
  public function getBundleConfigDependency($bundle) {
    // If this entity type uses entities to manage its bundles then depend on
    // the bundle entity.
    if ($bundle_entity_type_id = $this->getBundleEntityType()) {
917
      if (!$bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type_id)->load($bundle)) {
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
        throw new \LogicException(sprintf('Missing bundle entity, entity type %s, entity id %s.', $bundle_entity_type_id, $bundle));
      }
      $config_dependency = [
        'type' => 'config',
        'name' => $bundle_entity->getConfigDependencyName(),
      ];
    }
    else {
      // Depend on the provider of the entity type.
      $config_dependency = [
        'type' => 'module',
        'name' => $this->getProvider(),
      ];
    }

    return $config_dependency;
  }

936
}