public function populateMediaField($field_name) {
    $item = $this->item;
    $assets = [];
    if (!empty($item[$field_name])) {
      $data = $this->loadDataArray('media_image');

      foreach ($item[$field_name] as $k => $value) {
        if (!empty($data[$value])) {
          $name = $data[$value]['name'];
          $entities = $this->loadEntitiesByProperties('media', ['name' => $name]);

          foreach ($entities as $entity) {
            $assets[] = ['target_id' => $entity->id()];
          }
        }
      }
      return $assets;
    }
  }
public function populateMediaField($field_name) {
    $item = $this->item;
    $assets = [];
    if (!empty($item[$field_name])) {
      $data = $this->loadDataArray('media_image');

      foreach ($item[$field_name] as $k => $value) {
        if (!empty($data[$value])) {
          $name = $data[$value]['name'];
          $entities = $this->loadEntitiesByProperties('media', ['name' => $name]);

          foreach ($entities as $entity) {
            $assets[] = ['target_id' => $entity->id()];
          }
        }
      }
      return $assets;
    }
  }
public function populateMediaField ( $ field_name ) { $ item = $ this -> item ; $ assets = [ ] ; if ( ! empty ( $ item [ $ field_name ] ) ) { $ data = $ this -> loadDataArray ( 'media_image' ) ; foreach ( $ item [ $ field_name ] as $ k => $ value ) { if ( ! empty ( $ data [ $ value ] ) ) { $ name = $ data [ $ value ] [ 'name' ] ; $ entities = $ this -> loadEntitiesByProperties ( 'media' , [ 'name' => $ name ] ) ; foreach ( $ entities as $ entity ) { $ assets [ ] = [ 'target_id' => $ entity -> id ( ) ] ; } } } return $ assets ; } }
Finds a media asset by name.

@param string $field_name
Field name.

@return array
Returns media entities.
Finds a media asset by name .