Unverified Commit 47aac117 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3127026 Not possible to override an entity type class multiple times

By: mohit_aghera
By: edmargomes
By: john.nie
By: tim.plunkett
By: grimreaper
By: heddn
By: danielveza
By: dcam
By: mondrake
By: catch
By: larowlan
By: alexpott
(cherry picked from commit 22134b6d)
parent fc0b1524
Loading
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -66,6 +66,13 @@ class EntityType extends PluginDefinition implements EntityTypeInterface {
   */
  protected $originalClass;

  /**
   * The list of the classes when overridden.
   *
   * @var class-string[]
   */
  protected array $decoratedClasses = [];

  /**
   * An array of handlers.
   *
@@ -385,7 +392,10 @@ public function get($property) {
   * {@inheritdoc}
   */
  public function set($property, $value) {
    if (property_exists($this, $property)) {
    if ($property === 'class') {
      $this->setClass($value);
    }
    elseif (property_exists($this, $property)) {
      $this->{$property} = $value;
    }
    else {
@@ -452,15 +462,25 @@ public function getOriginalClass() {
    return $this->originalClass ?: $this->class;
  }

  /**
   * {@inheritdoc}
   */
  public function getDecoratedClasses(): array {
    return $this->decoratedClasses;
  }

  /**
   * {@inheritdoc}
   */
  public function setClass($class) {
    if (!$this->originalClass && $this->class) {
    if ($this->class) {
      if (!$this->originalClass) {
        // 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;
      }
      $this->decoratedClasses[] = $this->class;
    }

    return parent::setClass($class);
  }
+11 −0
Original line number Diff line number Diff line
@@ -68,6 +68,17 @@ public function set($property, $value);
   */
  public function getOriginalClass();

  /**
   * Gets the list of all the classes for this entity type.
   *
   * In case the class name was changed with setClass(), this will return
   * the list of all the changes.
   *
   * @return class-string[]
   *   The list of classes.
   */
  public function getDecoratedClasses(): array;

  /**
   * Gets an array of entity keys.
   *
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public function getEntityTypeFromClass($class_name) {
    $entity_type_id = NULL;
    $definitions = $this->entityTypeManager->getDefinitions();
    foreach ($definitions as $entity_type) {
      if ($entity_type->getOriginalClass() == $class_name || $entity_type->getClass() == $class_name) {
      if (in_array($class_name, $entity_type->getDecoratedClasses(), TRUE) || $entity_type->getClass() == $class_name) {
        $entity_type_id = $entity_type->id();
        if ($same_class++) {
          throw new AmbiguousEntityClassException($class_name);
+5 −0
Original line number Diff line number Diff line
name: 'Layout Builder Override Test'
type: module
description: 'Test layout builder override.'
package: Testing
version: VERSION
+14 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\layout_builder_override\Entity;

use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay as BaseEntityViewDisplay;

/**
 * Stub class to evaluate the override.
 */
class EntityViewDisplay extends BaseEntityViewDisplay implements EntityViewDisplayInterface {
}
Loading