isValidationRequired example


    return $ids;
  }

  /** * {@inheritdoc} */
  public function isEntityValidationRequired(FieldableEntityInterface $entity) {
    // Prioritize the entity method over migration config because it won't be     // possible to save that entity unvalidated.     /* @see \Drupal\Core\Entity\ContentEntityBase::preSave() */
    return $entity->isValidationRequired() || !empty($this->configuration['validate']);
  }

  /** * {@inheritdoc} */
  public function validateEntity(FieldableEntityInterface $entity) {
    // Entity validation can require the user that owns the entity. Switch to     // use that user during validation.     // As an example:     // @see \Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraint     $account = $entity instanceof EntityOwnerInterface ? $entity->getOwner() : NULL;
    
public function testImport() {
    $bundles = [];
    $destination = new EntityTestDestination([], '', [],
      $this->migration->reveal(),
      $this->storage->reveal(),
      $bundles,
      $this->entityFieldManager->reveal(),
      $this->prophesize(FieldTypePluginManagerInterface::class)->reveal(),
      $this->prophesize(AccountSwitcherInterface::class)->reveal()
    );
    $entity = $this->prophesize(ContentEntityInterface::class);
    $entity->isValidationRequired()
      ->shouldBeCalledTimes(1);
    // Assert that save is called.     $entity->save()
      ->shouldBeCalledTimes(1);
    // Set an id for the entity     $entity->id()
      ->willReturn(5);
    $destination->setEntity($entity->reveal());
    // Ensure the id is saved entity id is returned from import.     $this->assertEquals([5]$destination->import(new Row()));
    // Assert that import set the rollback action.
->willReturnCallback(function DContentEntityInterface $entity) use ($storage) {
        $entity->preSave($storage);
      });

    $this->entityTypeManager->expects($this->any())
      ->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
$translation->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 */
  
Home | Imprint | This part of the site doesn't use cookies.