setValidationRequired example

    $this->updateChangedTime($this->entity);
  }

  /** * {@inheritdoc} */
  public function buildEntity(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = parent::buildEntity($form$form_state);

    // Mark the entity as requiring validation.     $entity->setValidationRequired(!$form_state->getTemporaryValue('entity_validated'));

    // Save as a new revision if requested to do so.     if ($this->showRevisionUi() && !$form_state->isValueEmpty('revision')) {
      $entity->setNewRevision();
      if ($entity instanceof RevisionLogInterface) {
        // If a new revision is created, save the current user as         // revision author.         $entity->setRevisionUserId($this->currentUser()->id());
        $entity->setRevisionCreationTime($this->time->getRequestTime());
      }
    }

    
->method('getStorage')
      ->with($this->entityTypeId)
      ->willReturn($storage);

    // Check that entities can be saved normally when validation is not     // required.     $this->assertFalse($this->entity->isValidationRequired());
    $this->entity->save();

    // Make validation required and check that if the entity is validated, it     // can be saved normally.     $this->entity->setValidationRequired(TRUE);
    $this->assertTrue($this->entity->isValidationRequired());
    $this->entity->validate();
    $this->entity->save();

    // Check that the "validated" status is reset after saving the entity and     // that trying to save a non-validated entity when validation is required     // results in an exception.     $this->assertTrue($this->entity->isValidationRequired());
    $this->expectException(\AssertionError::class);
    $this->expectExceptionMessage('Entity validation was skipped.');
    $this->entity->save();
  }
$this->doTestInternalProperties($translation);
  }

  /** * Checks that internal properties are preserved for the specified entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * An entity object. */
  protected function doTestInternalProperties(ContentEntityInterface $entity) {
    $this->assertFalse($entity->isValidationRequired());
    $entity->setValidationRequired(TRUE);
    $this->assertTrue($entity->isValidationRequired());
    $new_revision = $this->storage->createRevision($entity);
    $this->assertTrue($new_revision->isValidationRequired());
  }

  /** * Tests that deleted translations are not accidentally restored. * * @covers ::createRevision */
  public function testRemovedTranslations() {
    
Home | Imprint | This part of the site doesn't use cookies.