Xpressengine\Editor\EditorHandler::get PHP Méthode

get() public méthode

Get editor by instance id
public get ( string $instanceId ) : AbstractEditor
$instanceId string instance id
Résultat AbstractEditor
    public function get($instanceId)
    {
        if (!($editorId = $this->getEditorId($instanceId))) {
            $editorId = $this->getDefaultEditorId();
        }
        $class = $this->register->get($editorId);
        /** @var AbstractEditor $editor */
        $editor = $this->container->make($class, ['instanceId' => $instanceId]);
        $editor->setConfig($this->configManager->getOrNew($this->getConfigKey($instanceId)));
        return $editor;
    }

Usage Example

 /**
  * file upload
  *
  * @param Request       $request      request
  * @param EditorHandler $handler      editor handler
  * @param Storage       $storage      storage
  * @param MediaManager  $mediaManager media manager
  * @param string        $instanceId   instance id
  * @return RendererInterface
  */
 public function fileUpload(Request $request, EditorHandler $handler, Storage $storage, MediaManager $mediaManager, $instanceId)
 {
     $uploadedFile = null;
     if ($request->file('file') !== null) {
         $uploadedFile = $request->file('file');
     } elseif ($request->file('image') !== null) {
         $uploadedFile = $request->file('image');
     }
     if ($uploadedFile === null) {
         throw new InvalidArgumentException();
     }
     $config = $handler->get($instanceId)->getConfig();
     if (!$config->get('uploadActive') || Gate::denies('upload', new Instance($handler->getPermKey($instanceId)))) {
         throw new AccessDeniedHttpException();
     }
     if ($config->get('fileMaxSize') * 1024 * 1024 < $uploadedFile->getSize()) {
         throw new HttpException(Response::HTTP_REQUEST_ENTITY_TOO_LARGE, xe_trans('xe::msgMaxFileSize', ['fileMaxSize' => $config->get('fileMaxSize'), 'uploadFileName' => $uploadedFile->getClientOriginalName()]));
     }
     $extensions = array_map(function ($v) {
         return trim($v);
     }, explode(',', $config->get('extensions', '')));
     if (array_search('*', $extensions) === false && !in_array(strtolower($uploadedFile->getClientOriginalExtension()), $extensions)) {
         throw new HttpException(Response::HTTP_NOT_ACCEPTABLE, xe_trans('xe::msgAvailableUploadingFiles', ['extensions' => $config->get('extensions'), 'uploadFileName' => $uploadedFile->getClientOriginalName()]));
     }
     $file = $storage->upload($uploadedFile, EditorHandler::FILE_UPLOAD_PATH);
     $media = null;
     $thumbnails = null;
     if ($mediaManager->is($file) === true) {
         $media = $mediaManager->make($file);
         $thumbnails = $mediaManager->createThumbnails($media, EditorHandler::THUMBNAIL_TYPE);
         $media = $media->toArray();
         if (!empty($thumbnails)) {
             $info['thumbnails'] = $thumbnails;
         }
     }
     return XePresenter::makeApi(['file' => $file->toArray(), 'media' => $media, 'thumbnails' => $thumbnails]);
 }