You are here

public function ImportEntity::save in Content Synchronizer 3.x

Saves an entity permanently.

When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures an exception is thrown.

Overrides EntityBase::save

File

src/Entity/ImportEntity.php, line 317

Class

ImportEntity
Defines the Import entity.

Namespace

Drupal\content_synchronizer\Entity

Code

public function save() {
  $name = $this
    ->getName();
  if (empty($name)) {

    /** @var \Drupal\file\Entity\File $file */
    $file = $this
      ->get(static::FIELD_ARCHIVE)
      ->referencedEntities()[0];
    $this
      ->setName(basename($file
      ->getFileUri()));
  }
  return parent::save();
}