You are here

public function AssetContainer::add in Mini site 8

Add asset to the list.

File

src/AssetContainer.php, line 36

Class

AssetContainer
Class Asset.

Namespace

Drupal\minisite

Code

public function add($entity_type, $entity_bundle, $entity_id, $entity_language, $field_name, $file_uri) {
  $asset = new Asset($entity_type, $entity_bundle, $entity_id, $entity_language, $field_name, $file_uri);

  // We need to check if provided asset URI already exists and use currently
  // provided asset fields to allow updating of existing asset in the DB.
  $existing_asset = Asset::loadByUri($file_uri);
  if ($existing_asset) {
    $asset
      ->setId($existing_asset
      ->id());
  }
  $this->assets[$file_uri] = $asset;
}