protected function importMediaImages() {
    $data = $this->loadDataArray('media_image');
    if (!empty($data)) {

      $uuids = [];

      foreach ($data as $item) {

        // Prepare content.
        $values = [
          'bundle' => $item['bundle'],
          'name' => $item['name'],
        ];

        $file = $this->saveFile($item['file']);

        if (!empty($file) && $file instanceof File) {
          $values['field_media_image'] = [
            'target_id' => $file->id(),
            'alt' => $item['alt'],
          ];
        }

        // Set author.
        $values['uid'] = 1;

        // Create Media.
        $entity = $this->entityTypeManager->getStorage('media')->create($values);
        $entity->save();
        $uuids[$entity->uuid()] = 'media';
      }
      $this->storeCreatedContentUuids($uuids);
    }
    return $this;
  }
protected function importMediaImages() {
    $data = $this->loadDataArray('media_image');
    if (!empty($data)) {

      $uuids = [];

      foreach ($data as $item) {

        // Prepare content.
        $values = [
          'bundle' => $item['bundle'],
          'name' => $item['name'],
        ];

        $file = $this->saveFile($item['file']);

        if (!empty($file) && $file instanceof File) {
          $values['field_media_image'] = [
            'target_id' => $file->id(),
            'alt' => $item['alt'],
          ];
        }

        // Set author.
        $values['uid'] = 1;

        // Create Media.
        $entity = $this->entityTypeManager->getStorage('media')->create($values);
        $entity->save();
        $uuids[$entity->uuid()] = 'media';
      }
      $this->storeCreatedContentUuids($uuids);
    }
    return $this;
  }
protected function importMediaImages ( ) { $ data = $ this -> loadDataArray ( 'media_image' ) ; if ( ! empty ( $ data ) ) { $ uuids = [ ] ; foreach ( $ data as $ item ) { // Prepare content. $ values = [ 'bundle' => $ item [ 'bundle' ] , 'name' => $ item [ 'name' ] , ] ; $ file = $ this -> saveFile ( $ item [ 'file' ] ) ; if ( ! empty ( $ file ) && $ file instanceof File ) { $ values [ 'field_media_image' ] = [ 'target_id' => $ file -> id ( ) , 'alt' => $ item [ 'alt' ] , ] ; } // Set author. $ values [ 'uid' ] = 1 ; // Create Media. $ entity = $ this -> entityTypeManager -> getStorage ( 'media' ) -> create ( $ values ) ; $ entity -> save ( ) ; $ uuids [ $ entity -> uuid ( ) ] = 'media' ; } $ this -> storeCreatedContentUuids ( $ uuids ) ; } return $ this ; }
Import media assets.
Import media assets .