38 lines
1.0 KiB
PHP
38 lines
1.0 KiB
PHP
<?php
|
|
namespace App\CMS\Pipeline\SavePipeline\Process;
|
|
|
|
use App\CMS\Contracts\Content\SavePipeline\Process;
|
|
use App\CMS\Helpers\RootDirectory;
|
|
use App\Models\Content\Content;
|
|
use App\Models\FileManager\File;
|
|
|
|
class UploadTitlePhoto implements Process
|
|
{
|
|
/**
|
|
* Process and modify given page
|
|
*
|
|
* @param Content $page
|
|
* @param array $input
|
|
*
|
|
* @return void
|
|
*/
|
|
function handle(Content & $page, array & $input)
|
|
{
|
|
$fileModel = app(File::class);
|
|
$titlePhoto = isset($input['titlePhotoFile']) ? $input['titlePhotoFile'] : null;
|
|
|
|
// upload file - if provided
|
|
$page->titlePhoto = isset($input['existingTitlePhoto']) ? $input['existingTitlePhoto'] : null;
|
|
|
|
if (!is_null($titlePhoto)) {
|
|
$root = RootDirectory::get();
|
|
$data = ['directoryId' => $root->id];
|
|
|
|
$file = $fileModel->upload($titlePhoto, (object)$data);
|
|
|
|
$page->titlePhoto = $file ? $file['filename'] : null;
|
|
}
|
|
|
|
$page->save();
|
|
}
|
|
} |