defaultData(); $clazz = $this->getCurrentClass(); $instance = $this->getCurrentInstance(); $hasWriteAccess = $this->hasWriteAccess($instance->getUri()) && $this->hasWriteAccessByContext(new Context([ Context::PARAM_CONTROLLER => self::class, Context::PARAM_ACTION => __FUNCTION__, ])); $myFormContainer = new editInstanceForm( $clazz, $instance, [ FormContainer::CSRF_PROTECTION_OPTION => true, FormContainer::IS_DISABLED => !$hasWriteAccess, editInstanceForm::IS_REPLACE_ASSET_DISABLED => !$this->hasWriteAccessByContext( new Context([ Context::PARAM_CONTROLLER => MediaImport::class, Context::PARAM_ACTION => 'editMedia', ]) ), FormContainer::ATTRIBUTE_VALIDATORS => [ 'data-depends-on-property' => [ $this->getDependsOnPropertyValidator(), ], ], ] ); $myForm = $myFormContainer->getForm(); if ($hasWriteAccess && $myForm->isSubmited() && $myForm->isValid()) { $values = $myForm->getValues(); // save properties $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($instance); $instance = $binder->bind($values); $message = __('Instance saved'); $this->setData('message', $message); $this->setData('reload', true); } $this->setData( 'isPreviewEnabled', $this->hasReadAccessByContext( new Context([ Context::PARAM_CONTROLLER => self::class, Context::PARAM_ACTION => 'isPreviewEnabled', ]) ) ); $this->setData('formTitle', __('Edit Instance')); $this->setData('myForm', $myForm->render()); try { $uri = $this->hasRequestParameter('id') ? $this->getRequestParameter('id') : $this->getRequestParameter('uri'); $mediaSource = new MediaSource([]); $fileInfo = $mediaSource->getFileInfo($uri); $mimeType = $fileInfo['mime']; $xml = in_array( $mimeType, [ 'application/xml', 'text/xml', MediaService::SHARED_STIMULUS_MIME_TYPE ], true ); $url = \tao_helpers_Uri::url( 'getFile', 'MediaManager', 'taoMediaManager', [ 'uri' => $uri, ] ); } catch (tao_models_classes_FileNotFoundException $e) { $this->setData('error', __('No file found for this media')); } $this->setData('xml', $xml); $this->setData('fileurl', $url); $this->setData('mimeType', $mimeType); $this->setView('form.tpl'); } /** * Get the file stream associated to given uri GET parameter * * @throws \common_exception_Error * @throws tao_models_classes_FileNotFoundException */ public function getFile() { if (!$this->hasGetParameter('uri')) { throw new \common_exception_Error('invalid media identifier'); } $uri = urldecode($this->getGetParameter('uri')); $mediaSource = new MediaSource([]); $fileInfo = $mediaSource->getFileInfo($uri); $fileManagement = $this->getServiceLocator()->get(FileManagement::SERVICE_ID); $stream = $fileManagement->getFileStream($fileInfo['link']); if ($fileInfo['mime'] === MediaService::SHARED_STIMULUS_MIME_TYPE) { $this->response = $this->getPsrResponse()->withBody($stream); } elseif ($this->hasGetParameter('xml')) { $this->returnJson(htmlentities((string)$stream)); } else { $this->setContentHeader($fileInfo['mime']); if ($this->getServiceLocator()->get(ContentDetector::class)->isGzip($stream)) { $this->response = $this->getPsrResponse()->withHeader('Content-Encoding', 'gzip'); } $this->response = $this->getPsrResponse()->withBody($stream); } } /** * @inheritDoc * * @requiresRight id WRITE */ public function delete() { return parent::delete(); } /** * overwrite the parent moveAllInstances to add the requiresRight only in Items * @see tao_actions_TaoModule::moveResource() */ public function moveResource() { return parent::moveResource(); } /** * @requiresRight id READ */ public function editClassLabel() { parent::editClassLabel(); } /** * @requiresRight id WRITE */ public function authoring() { //This method is required to hide button on FE based on ACL } protected function getClassService() { return $this->getServiceLocator()->get(MediaService::class); } private function getDependsOnPropertyValidator(): ValidatorInterface { return $this->getPsrContainer()->get(DependsOnPropertyValidator::class); } }