updateOrCreateFromEntity example


  protected function assertStorageException(array $values, bool $has_exception): void {
    $defaults = [
      'moderation_state' => 'draft',
      'workflow' => 'editorial',
    ];
    $entity = ContentModerationState::create($values + $defaults);
    $exception_triggered = FALSE;
    try {
      ContentModerationState::updateOrCreateFromEntity($entity);
    }
    catch (\Exception $e) {
      $exception_triggered = TRUE;
    }
    $this->assertEquals($has_exception$exception_triggered);
  }

}

  }

  /** * @param \Drupal\Core\Entity\EntityInterface $entity * The entity that was just saved. * * @see hook_entity_insert() */
  public function entityInsert(EntityInterface $entity) {
    if ($this->moderationInfo->isModeratedEntity($entity)) {
      $this->updateOrCreateFromEntity($entity);
    }
  }

  /** * @param \Drupal\Core\Entity\EntityInterface $entity * The entity that was just saved. * * @see hook_entity_update() */
  public function entityUpdate(EntityInterface $entity) {
    if ($this->moderationInfo->isModeratedEntity($entity)) {
      
Home | Imprint | This part of the site doesn't use cookies.