예제 #1
0
 /**
  * Create the edit mask.
  *
  * @return string
  *
  * @throws DcGeneralRuntimeException         If the data container is not editable, closed.
  *
  * @throws DcGeneralInvalidArgumentException If an unknown property is encountered in the palette.
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function execute()
 {
     $environment = $this->getEnvironment();
     $definition = $this->getDataDefinition();
     $dataProvider = $environment->getDataProvider($this->model->getProviderName());
     $dataProviderDefinition = $definition->getDataProviderDefinition();
     $dataProviderInformation = $dataProviderDefinition->getInformation($this->model->getProviderName());
     $inputProvider = $environment->getInputProvider();
     $palettesDefinition = $definition->getPalettesDefinition();
     $blnSubmitted = $inputProvider->getValue('FORM_SUBMIT') === $definition->getName();
     $blnIsAutoSubmit = $inputProvider->getValue('SUBMIT_TYPE') === 'auto';
     $widgetManager = new ContaoWidgetManager($environment, $this->model);
     $this->checkEditable($this->model);
     $this->checkCreatable($this->model);
     $environment->getEventDispatcher()->dispatch(PreEditModelEvent::NAME, new PreEditModelEvent($environment, $this->model));
     $this->view->enforceModelRelationship($this->model);
     // Pass 1: Get the palette for the values stored in the model.
     $palette = $palettesDefinition->findPalette($this->model);
     $propertyValues = $this->processInput($widgetManager);
     if ($blnSubmitted && $propertyValues) {
         // Pass 2: Determine the real palette we want to work on if we have some data submitted.
         $palette = $palettesDefinition->findPalette($this->model, $propertyValues);
         // Update the model - the model might add some more errors to the propertyValueBag via exceptions.
         $this->getEnvironment()->getController()->updateModelFromPropertyBag($this->model, $propertyValues);
     }
     $fieldSets = $this->buildFieldSet($widgetManager, $palette, $propertyValues);
     if (!$blnIsAutoSubmit && $blnSubmitted && empty($this->errors)) {
         $this->doPersist();
         $this->handleSubmit($this->model);
     }
     $objTemplate = new ContaoBackendViewTemplate('dcbe_general_edit');
     $objTemplate->setData(array('fieldsets' => $fieldSets, 'versions' => $dataProviderInformation->isVersioningEnabled() ? $dataProvider->getVersions($this->model->getId()) : null, 'subHeadline' => $this->getHeadline(), 'table' => $definition->getName(), 'enctype' => 'multipart/form-data', 'error' => $this->errors, 'editButtons' => $this->getEditButtons(), 'noReload' => (bool) $this->errors, 'breadcrumb' => $this->breadcrumb));
     if (in_array('ContaoCommunityAlliance\\DcGeneral\\Data\\MultiLanguageDataProviderInterface', class_implements($environment->getDataProvider($this->model->getProviderName())))) {
         /** @var MultiLanguageDataProviderInterface $dataProvider */
         $langsNative = array();
         require TL_ROOT . '/system/config/languages.php';
         $objTemplate->set('languages', $environment->getController()->getSupportedLanguages($this->model->getId()))->set('language', $dataProvider->getCurrentLanguage())->set('languageHeadline', $langsNative[$dataProvider->getCurrentLanguage()]);
     } else {
         $objTemplate->set('languages', null)->set('languageHeadline', '');
     }
     return $objTemplate->parse();
 }