3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\Core\Config\Entity\ConfigEntityInterface;
9 * Base class for config entity types with settings for form and view modes.
11 abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityDisplayModeInterface {
14 * The ID of the form or view mode.
21 * The human-readable name of the form or view mode.
28 * The entity type this form or view mode is used for.
30 * This is not to be confused with EntityDisplayModeBase::$entityType which is
31 * inherited from Entity::$entityType.
35 protected $targetEntityType;
38 * Whether or not this form or view mode has custom settings by default.
40 * If FALSE, entities displayed in this mode will reuse the 'default' display
41 * settings by default (e.g. right after the module exposing the form or view
42 * mode is enabled), but administrators can later use the Field UI to apply
43 * custom display settings specific to the form or view mode.
47 protected $status = TRUE;
50 * Whether or not the rendered output of this view mode is cached by default.
54 protected $cache = TRUE;
59 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
60 /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $a */
61 /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $b */
62 // Sort by the type of entity the view mode is used for.
63 $a_type = $a->getTargetType();
64 $b_type = $b->getTargetType();
65 $type_order = strnatcasecmp($a_type, $b_type);
66 return $type_order != 0 ? $type_order : parent::sort($a, $b);
72 public function getTargetType() {
73 return $this->targetEntityType;
79 public function setTargetType($target_entity_type) {
80 $this->targetEntityType = $target_entity_type;
87 public function calculateDependencies() {
88 parent::calculateDependencies();
89 $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType);
90 $this->addDependency('module', $target_entity_type->getProvider());
97 public function preSave(EntityStorageInterface $storage) {
98 parent::preSave($storage);
99 \Drupal::entityManager()->clearCachedFieldDefinitions();
105 public static function preDelete(EntityStorageInterface $storage, array $entities) {
106 parent::preDelete($storage, $entities);
107 \Drupal::entityManager()->clearCachedFieldDefinitions();