Commit a50f3715 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3306168: Payload error

parent a37d440d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -57,8 +57,8 @@ final class Payload extends PayloadBase {
  /**
   * {@inheritdoc}
   */
  public static function createFromArray(array $payload): PayloadInterface {
    return new static();
  public static function createFromArray(array $payload): ?PayloadInterface {
    return new Payload();
  }

  /**
+9 −16
Original line number Diff line number Diff line
@@ -107,25 +107,12 @@ final class Payload extends PayloadBase {
  /**
   * {@inheritdoc}
   */
  public static function createFromArray(array $payload): PayloadInterface {
  public static function createFromArray(array $payload): ?PayloadInterface {
    try {
      $storage = \Drupal::entityTypeManager()->getStorage($payload['entity']['type']);
    }
    catch (InvalidPluginDefinitionException $e) {
    }
    catch (PluginNotFoundException $e) {
    }
    /** @noinspection IsEmptyFunctionUsageInspection */
    if (empty($storage)) {
      // Entity type does not exist anymore, created a dummy entity and don't save it.
      $entity = Event::create([
        'label' => 'Content type ' . $payload['entity']['type'] . ' no longer exists.',
      ]);
    }
    else {
      /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
      $entity = $storage->load($payload['entity']['id']);
      if (empty($entity)) {
      if ($entity === NULL) {
        // Entity got deleted, created a dummy entity and don't save it.
        $entity = $storage->create([
          $storage->getEntityType()->getKey('bundle') => $payload['entity']['bundle'],
@@ -134,7 +121,13 @@ final class Payload extends PayloadBase {
        ]);
      }
    }
    return new static($entity);
    catch (InvalidPluginDefinitionException | PluginNotFoundException $e) {
      // Entity type does not exist, create a dummy entity and don't save it.
      $entity = Event::create([
        'label' => 'Content type ' . $payload['entity']['type'] . ' no longer exists.',
      ]);
    }
    return new Payload($entity);
  }

  /**
+3 −2
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ use Drupal\danse\Entity\Event;
use Drupal\danse\Entity\EventInterface;
use Drupal\danse\PayloadBase;
use Drupal\danse\PayloadInterface;
use Drupal\Core\Form\FormState;

/**
 * Class Payload.
@@ -71,8 +72,8 @@ final class Payload extends PayloadBase {
  /**
   * {@inheritdoc}
   */
  public static function createFromArray(array $payload): PayloadInterface {
    return new static($payload['form'], unserialize($payload['form_state'], ['allowed_classes' => ['Drupal\Core\Form\FormState']]));
  public static function createFromArray(array $payload): ?PayloadInterface {
    return new Payload($payload['form'], unserialize($payload['form_state'], ['allowed_classes' => [FormState::class]]));
  }

  /**
+2 −2
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ final class Payload extends PayloadBase {
  /**
   * {@inheritdoc}
   */
  public static function createFromArray(array $payload): PayloadInterface {
    return new static(
  public static function createFromArray(array $payload): ?PayloadInterface {
    return new Payload(
      $payload['level'],
      $payload['message'],
      $payload['context']
+5 −3
Original line number Diff line number Diff line
@@ -65,10 +65,12 @@ final class Payload extends PayloadBase {
  /**
   * {@inheritdoc}
   */
  public static function createFromArray(array $payload): PayloadInterface {
  public static function createFromArray(array $payload): ?PayloadInterface {
    /** @var \Drupal\user\UserInterface $user */
    $user = User::load($payload['account']);
    return new static($user);
    if ($user = User::load($payload['account'])) {
      return new Payload($user);
    }
    return NULL;
  }

  /**
Loading