/**
  * Manages the constants by setting the new values put in the fields, and
  * linking the pages of the model site with the duplicated one's.
  */
 public function run()
 {
     ConstantManagerUtility::manageTemplateConstants($this->getModelPageUid(), $this->getDuplicatedPageUid(), $this->getFieldsValues(), $this->getDuplicationData('pagesUidAssociation'));
 }
 /**
  * Contains the main form for the creation of a new site.
  *
  * If the form has been submitted, fields' values will be checked so they
  * must match their rules declared in the main configuration. If no error
  * occurs, the site duplication process will start.
  *
  * If the argument "modifySite" is sent, the site has already been
  * duplicated and saved, and the form will be filled with the already saved
  * configuration of this site.
  *
  * @throws \Exception
  */
 public function newAction()
 {
     // Models sites which can be duplicated.
     $modelSites = FieldsConfigurationPresets::getModelSitesList();
     if (empty($modelSites)) {
         $this->view->assign('noModelSite', true);
     } else {
         // Getting the selected model site. If none has been submitted, the default one (first one in the list) is used.
         $selectedModelSite = $this->request->hasArgument('fields') && isset($this->request->getArgument('fields')['modelSite']) ? $this->request->getArgument('fields')['modelSite'] : key($modelSites);
         if (!$selectedModelSite) {
             throw new \Exception('Fatal error: the module should have a model site value.', 1423830741);
         }
         if (!Core::checkUidIsModelSite($selectedModelSite)) {
             throw new \Exception('Fatal error: the model site "' . $selectedModelSite . '" is not a correct value.', 1423830834);
         }
         $checkHideInSiteModification = false;
         // Checking if a site is being edited, and if the uid of this site is correct.
         $modifySite = null;
         if ($this->request->hasArgument('modifySite')) {
             $modifySite = intval($this->request->getArgument('modifySite'));
             Core::checkUidIsSavedSite($modifySite);
             $checkHideInSiteModification = true;
         }
         if ($modifySite !== null) {
             $pageUid = $this->request->getArgument('modifySite');
             $this->view->assign('modifySite', $pageUid);
             /** @var Save $savedSite */
             $savedSite = $this->saveRepository->findOneByRootPageUid($pageUid);
             $fields = $this->fillFieldsValuesFromSavedSite($savedSite, false);
         } else {
             $fields = Field::getFields($selectedModelSite, $checkHideInSiteModification);
         }
         // The form has been submitted, the site might be duplicated.
         if ($this->request->hasArgument('submitted')) {
             $this->processFormSubmit($fields);
         } else {
             $this->view->assign('refreshForm', true);
             if ($modifySite === null) {
                 $constantsValues = ConstantManagerUtility::getTemplateConstantsValues($selectedModelSite, array_keys($fields));
                 foreach ($constantsValues as $fieldName => $fieldValue) {
                     $fields[$fieldName]->setValue($fieldValue);
                 }
             }
         }
         // Creating a unique id for the generated form.
         $this->view->assign('formId', 'SiteFactoryForm_' . md5(serialize($this)));
         $this->view->assign('fieldsConfiguration', $fields);
     }
 }