Sulu\Bundle\MediaBundle\Media\Manager\MediaManager::save PHP Méthode

save() public méthode

public save ( $uploadedFile, $data, $userId )
    public function save($uploadedFile, $data, $userId)
    {
        if (isset($data['id'])) {
            $media = $this->modifyMedia($uploadedFile, $data, $this->getUser($userId));
        } else {
            $media = $this->buildData($uploadedFile, $data, $this->getUser($userId));
        }
        return $this->addFormatsAndUrl($media);
    }

Usage Example

 /**
  * @{inheritdoc}
  */
 public function handle(FormInterface $form, $attributes = array())
 {
     if (!$form->isValid()) {
         return false;
     }
     $mediaIds = [];
     if ($form->has('files')) {
         $files = $form['files']->getData();
         if (count($files)) {
             $type = $this->formExtension->getType($form->getName());
             $collectionId = $type->getCollectionId();
             $ids = [];
             /** @var UploadedFile $file */
             foreach ($form['files']->getData() as $file) {
                 if ($file instanceof UploadedFile) {
                     $media = $this->mediaManager->save($file, ['collection' => $collectionId, 'locale' => $form->get('locale')->getData(), 'title' => $file->getClientOriginalName()], null);
                     $ids[] = $media->getId();
                 }
             }
             $mediaIds['files'] = $ids;
         }
     }
     $attributes['form'] = $form;
     $this->saveForm($form, $attributes, $mediaIds);
     $type = $this->formExtension->getType($form->getName());
     if ($type instanceof TypeInterface) {
         $this->sendMails($type, $attributes, $form);
     }
     return true;
 }
All Usage Examples Of Sulu\Bundle\MediaBundle\Media\Manager\MediaManager::save