Verified Commit 54575357 authored by Dave Long's avatar Dave Long
Browse files

perf: #3572348 Static cache EntityDataDefinition::getDataType()

By: catch
(cherry picked from commit efe74934)
parent d8e08b13
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -9,6 +9,11 @@
 */
class EntityDataDefinition extends ComplexDataDefinitionBase implements EntityDataDefinitionInterface {

  /**
   * The data type for this entity.
   */
  protected ?string $dataType;

  /**
   * Creates a new entity definition.
   *
@@ -98,6 +103,9 @@ public function getPropertyDefinitions() {
   * {@inheritdoc}
   */
  public function getDataType() {
    if (isset($this->dataType)) {
      return $this->dataType;
    }
    $type = 'entity';
    if ($entity_type = $this->getEntityTypeId()) {
      $type .= ':' . $entity_type;
@@ -110,6 +118,7 @@ public function getDataType() {
        }
      }
    }
    $this->dataType = $type;
    return $type;
  }

@@ -160,4 +169,12 @@ public function setBundles(?array $bundles = NULL) {
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function __sleep(): array {
    $this->dataType = NULL;
    return parent::__sleep();
  }

}