/** * Create a form from a table where the fields can prefilled, * configured via TypoScript. * * @param array $config Config array * @param string $step Current step * @param bool $parseList Parse list * * @return string Form HTML */ public function getInputForm(array $config, $step, $parseList = TRUE) { $hookObjectsArr = $this->getHookObjectArray('processInputForm'); // Build a query for selecting an address from database // if we have a logged in user if ($parseList) { $fieldList = $this->parseFieldList($config['sourceFields.']); } else { $fieldList = array_keys($config['sourceFields.']); } $this->dbFieldData = $this->sessionData[$step]; $fieldTemplate = $this->cObj->getSubpart($this->templateCode, '###SINGLE_INPUT###'); $fieldTemplateCheckbox = $this->cObj->getSubpart($this->templateCode, '###SINGLE_CHECKBOX###'); $fieldTemplateHidden = $this->cObj->getSubpart($this->templateCode, '###SINGLE_HIDDEN###'); // backward compatibility if ($fieldTemplateHidden == '') { $fieldTemplateHidden = $fieldTemplate; } $fieldCode = ''; foreach ($fieldList as $fieldName) { $fieldMarkerArray = array(); $fieldLabel = $this->pi_getLL($step . '_' . $fieldName, $this->pi_getLL('general_' . $fieldName)); if ($config['sourceFields.'][$fieldName . '.']['mandatory'] == '1') { $fieldLabel .= ' ' . $this->cObj->stdWrap($config['mandatorySign'], $config['mandatorySignStdWrap.']); } $fieldMarkerArray['###FIELD_LABEL###'] = $fieldLabel; // Clear the error field, this has to be implemented in future versions if (strlen($this->formError[$fieldName]) > 0) { $fieldMarkerArray['###FIELD_ERROR###'] = $this->cObj->stdWrap($this->formError[$fieldName], $config['fielderror.']); } else { $fieldMarkerArray['###FIELD_ERROR###'] = ''; } // Create input field $arrayName = $fieldName . ($parseList ? '.' : ''); $fieldMarkerArray['###FIELD_INPUT###'] = $this->getInputField($fieldName, $config['sourceFields.'][$arrayName], GeneralUtility::removeXSS(strip_tags($this->sessionData[$step][$fieldName])), $step); $fieldMarkerArray['###FIELD_NAME###'] = $this->prefixId . '[' . $step . '][' . $fieldName . ']'; $fieldMarkerArray['###FIELD_INPUTID###'] = $step . '-' . $fieldName; // Save some data for mails $this->sessionData['mails'][$step][$fieldName] = array('data' => $this->sessionData[$step][$fieldName], 'label' => $fieldLabel); if ($config['sourceFields.'][$arrayName]['type'] == 'check') { $fieldCodeTemplate = $fieldTemplateCheckbox; } elseif ($config['sourceFields.'][$arrayName]['type'] == 'hidden') { $fieldCodeTemplate = $fieldTemplateHidden; } else { $fieldCodeTemplate = $fieldTemplate; } foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processInputForm')) { $hookObj->processInputForm($fieldName, $fieldMarkerArray, $config, $step, $fieldCodeTemplate, $this); } } $fieldCode .= $this->cObj->substituteMarkerArray($fieldCodeTemplate, $fieldMarkerArray); } $GLOBALS['TSFE']->fe_user->setKey('ses', Tx_Commerce_Utility_GeneralUtility::generateSessionKey('mails'), $this->sessionData['mails']); return $fieldCode; }
/** * Returns HTML form for a single address. The fields are fetched from * tt_address and configured in TS. * * @param string $action Action that should be performed (can be "new" or "edit") * @param int $addressUid UID of the page where the addresses are stored * @param array $config Configuration array for all fields * * @return string HTML code with the form for editing an address */ protected function getAddressForm($action = 'new', $addressUid = NULL, array $config) { $hookObjectsArr = array(); if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi4/class.tx_commerce_pi4.php']['getAddressFormItem'])) { \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog(' hook $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/pi4/class.tx_commerce_pi4.php\'][\'getAddressFormItem\'] is deprecated since commerce 1.0.0, it will be removed in commerce 1.4.0, please use instead $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'commerce/Classes/Controller/AddressesController.php\'][\'getAddressFormItem\'] '); foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/pi4/class.tx_commerce_pi4.php']['getAddressFormItem'] as $classRef) { $hookObjectsArr[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); } } if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/AddressesController.php']['getAddressFormItem'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['commerce/Classes/Controller/AddressesController.php']['getAddressFormItem'] as $classRef) { $hookObjectsArr[] = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef); } } $addressType = 1; if (!empty($this->piVars['addressType'])) { $addressType = (int) $this->piVars['addressType']; } switch ($addressType) { case '2': $addressType = 'delivery'; break; default: $addressType = 'billing'; } // Build query to select an address from the database if user is logged in $addressData = $addressUid != NULL ? $this->addresses[$addressUid] : array(); if ($this->formErrors()) { $addressData = $this->piVars; } $addressData = Tx_Commerce_Utility_GeneralUtility::removeXSSStripTagsArray($addressData); if ($addressData['tx_commerce_address_type_id'] == NULL) { $addressData['tx_commerce_address_type_id'] = (int) $this->piVars['addressType']; } // Get the templates if ($this->conf[$addressType . '.']['subpartMarker.']['editWrap']) { $tplBase = $this->cObj->getSubpart($this->templateCode, strtoupper($this->conf[$addressType . '.']['subpartMarker.']['editWrap'])); } else { $tplBase = $this->cObj->getSubpart($this->templateCode, '###ADDRESS_EDIT###'); } if ($this->conf[$addressType . '.']['subpartMarker.']['editItem']) { $tplForm = $this->cObj->getSubpart($this->templateCode, strtoupper($this->conf[$addressType . '.']['subpartMarker.']['editItem'])); } else { $tplForm = $this->cObj->getSubpart($this->templateCode, '###ADDRESS_EDIT_FORM###'); } if ($this->conf[$addressType . '.']['subpartMarker.']['editField']) { $tplField = $this->cObj->getSubpart($this->templateCode, strtoupper($this->conf[$addressType . '.']['subpartMarker.']['editField'])); } else { $tplField = $this->cObj->getSubpart($this->templateCode, '###SINGLE_INPUT###'); } // Create form fields $fieldsMarkerArray = array(); foreach ($this->fieldList as $fieldName) { $fieldMarkerArray = array(); $lowerName = strtolower($fieldName); // Get field label $fieldLabel = $this->pi_getLL('label_' . $lowerName, $fieldName); // Check if the field is manadatory and append the mandatory sign to the label if ($config['formFields.'][$fieldName . '.']['mandatory'] == '1') { $fieldLabel .= ' ' . $config['mandatorySign']; } // Insert error message for this specific field if (strlen($this->getFormError($fieldName)) > 0) { $fieldMarkerArray['###FIELD_ERROR###'] = $this->getFormError($fieldName); } else { $fieldMarkerArray['###FIELD_ERROR###'] = ''; } // Create input field // In this version we only create some simple text fields. $fieldMarkerArray['###FIELD_INPUT###'] = $this->getInputField($fieldName, $config['formFields.'][$fieldName . '.'], $addressData[$fieldName]); // Get field item $fieldsMarkerArray['###FIELD_' . strtoupper($fieldName) . '###'] = $this->cObj->substituteMarkerArray($tplField, $fieldMarkerArray); $fieldsMarkerArray['###LABEL_' . strtoupper($fieldName) . '###'] = $fieldLabel; } foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processAddressfieldsMarkerArray')) { $fieldsMarkerArray = $hookObj->processAddressfieldsMarkerArray($fieldsMarkerArray, $tplField, $addressData, $action, $addressUid, $config, $this); } } // Merge fields with form template $formCode = $this->cObj->substituteMarkerArray($tplForm, $fieldsMarkerArray); // Create submit button and some hidden fields $submitCode = '<input type="hidden" name="' . $this->prefixId . '[action]" value="' . $action . '" />'; $submitCode .= '<input type="hidden" name="' . $this->prefixId . '[addressid]" value="' . $addressUid . '" />'; $submitCode .= '<input type="hidden" name="' . $this->prefixId . '[addressType]" value="' . $addressData['tx_commerce_address_type_id'] . '" />'; $submitCode .= '<input type="submit" name="' . $this->prefixId . '[check]" value="' . $this->pi_getLL('label_submit_edit') . '" />'; // Create a checkbox where the user can select if the address is his main // address / Changed to label and field $isMainAddressCodeField = '<input type="checkbox" name="' . $this->prefixId . '[ismainaddress]"'; if ($addressData['tx_commerce_is_main_address'] || $addressData['ismainaddress']) { $isMainAddressCodeField .= ' checked="checked"'; } $isMainAddressCodeField .= ' />'; $isMainAddressCodeLabel = $this->pi_getLL('label_is_main_address'); // Fill additional information if ($addressData['tx_commerce_address_type_id'] == 1) { $baseMarkerArray['###MESSAGE_EDIT###'] = $this->pi_getLL('message_edit_billing'); } elseif ($addressData['tx_commerce_address_type_id'] == 2) { $baseMarkerArray['###MESSAGE_EDIT###'] = $this->pi_getLL('message_edit_delivery'); } else { $baseMarkerArray['###MESSAGE_EDIT###'] = $this->pi_getLL('message_edit_unknown'); } // Fill the marker $baseMarkerArray['###ADDRESS_FORM_FIELDS###'] = $formCode; $baseMarkerArray['###ADDRESS_FORM_SUBMIT###'] = $submitCode; $baseMarkerArray['###ADDRESS_FORM_IS_MAIN_ADDRESS_FIELD###'] = $isMainAddressCodeField; $baseMarkerArray['###ADDRESS_FORM_IS_MAIN_ADDRESS_LABEL###'] = $isMainAddressCodeLabel; // @deprecated Obsolete Marker, use Field and label instead $baseMarkerArray['###ADDRESS_FORM_IS_MAIN_ADDRESS###'] = $isMainAddressCodeField . ' ' . $isMainAddressCodeLabel; $baseMarkerArray['###ADDRESS_TYPE###'] = $this->pi_getLL('label_address_of_type_' . $this->piVars['addressType']); // Get action link if ((int) $this->piVars['backpid'] > 0) { $link = $this->pi_linkTP_keepPIvars_url(); } else { $link = ''; } $baseMarkerArray['###ADDRESS_FORM_BACK###'] = $this->pi_linkToPage($this->pi_getLL('label_form_back', 'back'), $this->piVars['backpid'], '', array('tx_commerce_pi3' => array('step' => $GLOBALS['TSFE']->fe_user->getKey('ses', Tx_Commerce_Utility_GeneralUtility::generateSessionKey('currentStep'))))); foreach ($hookObjectsArr as $hookObj) { if (method_exists($hookObj, 'processAddressFormMarker')) { $hookObj->processAddressFormMarker($baseMarkerArray, $action, $addressUid, $addressData, $config, $this); } } return '<form method="post" action="' . $link . '" ' . $this->conf[$addressType . '.']['formParams'] . '>' . $this->cObj->substituteMarkerArray($tplBase, $baseMarkerArray) . '</form>'; }