コード例 #1
0
 /**
  * Generate the marker array to display the edit form
  *
  * @return array
  */
 public function renderEditForm()
 {
     $content = '';
     $markerArray = array();
     $markerArray['###INFOS###'] = '';
     $markerArray['###ERRORS###'] = '';
     // init
     if ($this->uid == 0) {
         // insert mode
         $record = $this->getEmptyRecord($this->fields);
         // generate ts additionnal markers for display only
         $markerArray = array_merge($markerArray, tx_t3devapi_miscellaneous::convertToMarkerArray($this->checkMappingValues(array(), $this->pObj->conf['insertMappingMarkers'])));
     } else {
         // edit mode
         $whereCondition = '';
         if (!empty($this->pObj->conf['whereEdit'])) {
             $whereCondition = ' ' . str_replace(array_keys($this->pObj->feuserMarkers), array_values($this->pObj->feuserMarkers), $this->pObj->conf['whereEdit']);
         }
         $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($this->table, $this->uid, $this->fields, $whereCondition);
         $this->currentRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($this->table, $this->uid, '*');
         if ($record === null) {
             return null;
         }
         // generate ts additionnal markers for display only
         $markerArray = array_merge($markerArray, tx_t3devapi_miscellaneous::convertToMarkerArray($this->checkMappingValues(array(), $this->pObj->conf['editMappingMarkers'])));
     }
     // if submit
     if (!empty($this->piVars['submit'])) {
         $datas = $this->getAllFormValues();
         // if no errors
         if (count($this->validation->getErrors()) === 0) {
             $datas = $this->formatAllFormValues($datas);
             if ($this->uid == 0) {
                 $this->insertRecord($datas);
             } else {
                 $this->updateRecord($datas);
                 $record = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($this->table, $this->uid, $this->fields);
             }
         } else {
             // TODO: remettre les files
             // fill all the fields with the current piVars
             $record = $this->getPiVarsRecord($this->fields);
             $record = $this->formatAllFormValues($record);
         }
     }
     // group fields by fieldset (--div--)
     if (!empty($this->pObj->conf['enableFieldset'])) {
         // get first tca types
         $tcaTypesFirst = each($this->tca['types']);
         $allFieldsWithFieldset = preg_split('/,\\s*(--div--\\s*;.*?),/', $tcaTypesFirst['value']['showitem'], 0, PREG_SPLIT_DELIM_CAPTURE);
         $recordWithFieldset = array();
         // generate all fields with fieldset
         $div = 'LLL:EXT:lang/locallang_core.php:labels.generalTab';
         foreach ($allFieldsWithFieldset as $fieldsWithFieldset) {
             if (stristr($fieldsWithFieldset, '--div--')) {
                 $divLabel = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $fieldsWithFieldset);
                 $div = $divLabel[1];
             } else {
                 $fields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldsWithFieldset);
                 foreach ($fields as $field) {
                     if (array_key_exists($field, $record)) {
                         $field = preg_replace('/;.*/', '', $field);
                         $recordWithFieldset[$div][] = $field;
                     }
                 }
             }
         }
         foreach ($recordWithFieldset as $fieldset => $fields) {
             $content .= '<fieldset><legend>' . $GLOBALS['LANG']->sL($fieldset) . '</legend>';
             foreach ($fields as $field) {
                 $val = $this->formatSpecialValueBeforeDisplay($field, $record[$field]);
                 $content .= $this->getFieldFromTca($field, $val);
                 $markerArray['###' . strtoupper($field) . '_VAL###'] = $val;
             }
             $content .= '</fieldset>';
         }
     } else {
         // classic rendering - generate all fields
         foreach ($record as $field => $val) {
             $val = $this->formatSpecialValueBeforeDisplay($field, $val);
             $content .= $this->getFieldFromTca($field, $val);
             $markerArray['###' . strtoupper($field) . '_VAL###'] = $val;
         }
     }
     // submit button
     $submit = tx_t3devapi_html::renderSubmit($this->getPrefix('submit'), $this->getLabel('submit'));
     $content .= tx_t3devapi_html::renderDiv($this->extKey . '_' . $this->pObj->cObj->data['uid'] . '_submit', $submit);
     // form wrap
     $content = tx_t3devapi_html::renderForm($this->formName, $content, array('action' => $this->actionUrl, 'enctype' => 'multipart/form-data', 'onsubmit' => $this->formName . 'Submit();'));
     // on submit JS (required for rtehtmlarea)
     $content = tx_t3devapi_html::renderScriptJs('function ' . $this->formName . 'Submit() { ' . $this->onSubmit . '}') . $content;
     if (!empty($this->piVars['submit'])) {
         if (count($this->validation->getErrors()) > 0) {
             // display errors
             $errorsList = $this->validation->getErrors();
             $errorsContent = '';
             $errorsContent .= '<div class="alert alert-error">' . $this->getLabel('errors') . '<ul>';
             foreach ($errorsList as $error) {
                 $errorsContent .= '<li>' . $error . '</li>';
             }
             $errorsContent .= '</ul></div>';
             $markerArray['###ERRORS###'] = $errorsContent;
         } else {
             // display infos
             $infosContent = '<div class="alert alert-success">' . $this->getLabel('updateok') . '</div>';
             $markerArray['###INFOS###'] = $infosContent;
         }
     }
     if (!empty($this->piVars['insertok'])) {
         $infosContent = '<div class="alert alert-success">' . $this->getLabel('updateok') . '</div>';
         $markerArray['###INFOS###'] = $infosContent;
     }
     // add js if needed
     $content .= $this->getAddjs();
     $markerArray['###FORM###'] = $content;
     return $markerArray;
 }
コード例 #2
0
 /**
  * renderIf
  *
  * @test
  */
 public function renderIf()
 {
     $markersArray = tx_t3devapi_miscellaneous::convertToMarkerArray(array('i' => 1, 'uid' => 1));
     $htmlGenerated = $this->template->renderAllTemplate($markersArray, '###ITEM_IF###');
     $this->assertEquals($htmlGenerated, $this->getContentTemplateFile('renderIf.html'));
 }