public function modifyPalette(\DataContainer $objDc, $blnFrontend = false) { // modify palette for backend view, based on archive submissionFields if (!$blnFrontend) { \Controller::loadDataContainer('tl_submission'); $arrDca =& $GLOBALS['TL_DCA']['tl_submission']; if (($objSubmission = \HeimrichHannot\Submissions\SubmissionModel::findByPk($objDc->id)) === null) { return false; } if (($objSubmissionArchive = $objSubmission->getRelated('pid')) === null) { return false; } $arrDca['palettes']['defaultBackup'] = $arrDca['palettes']['default']; $arrSubmissionFields = deserialize($objSubmissionArchive->submissionFields, true); // remove subpalette fields from arrSubmissionFields if (is_array($arrDca['subpalettes'])) { foreach ($arrDca['subpalettes'] as $key => $value) { $arrSubpaletteFields = \HeimrichHannot\FormHybrid\FormHelper::getPaletteFields($objDc->table, $value); if (!is_array($arrSubpaletteFields)) { continue; } $arrSubmissionFields = array_diff($arrSubmissionFields, $arrSubpaletteFields); } } $arrDca['palettes']['default'] = str_replace('submissionFields', implode(',', $arrSubmissionFields), \HeimrichHannot\Submissions\Submissions::PALETTE_DEFAULT); } // overwrite attachment config with archive if (isset($arrDca['fields']['attachments']) && $objSubmissionArchive->addAttachmentConfig) { $arrConfig = Arrays::filterByPrefixes($objSubmissionArchive->row(), array('attachment')); foreach ($arrConfig as $strKey => $value) { $strKey = lcfirst(str_replace('attachment', '', $strKey)); $arrDca['fields']['attachments']['eval'][$strKey] = $value; } } }
/** * Retrieve the subpalette by the field selector * * @param string $strSelector * @param array $arrFields * * @return array Return the state, subpalette name, the filtered fields array and autosubmit state */ protected function retrieveSubpaletteWithState($strSelector, array $arrFields) { $blnActive = null; $blnAutoSubmit = false; $strSubpalette = null; $arrSubPaletteFields = array(); $blnToggleSubpalette = false; $varValue = $this->getFieldValue($strSelector); // skip arrays, they cant be array keys if (is_array($varValue)) { return array($blnActive, $strSubpalette, $arrFields, $blnAutoSubmit); } // checkbox: addImage for example if ($this->dca['fields'][$strSelector]['inputType'] == 'checkbox' && !$this->dca['fields'][$strSelector]['eval']['multiple']) { if (strlen($this->dca['subpalettes'][$strSelector])) { $blnActive = $varValue == true; $strSubpalette = $strSelector; $blnToggleSubpalette = true; $arrSubPaletteFields = FormHelper::getPaletteFields($this->strTable, $this->dca['subpalettes'][$strSubpalette]); } } else { // type selector if (isset($this->dca['subpalettes'][$varValue])) { $blnAutoSubmit = true; $blnActive = true; $strSubpalette = $varValue; } elseif (is_array($this->dca['subpalettes'])) { $arrSubpalettes = Arrays::filterByPrefixes($this->dca['subpalettes'], array($strSelector . '_')); if (!empty($arrSubpalettes)) { $blnToggleSubpalette = true; // also if no active type selector, cause no default value, toggleSubpalette $blnActive = isset($arrSubpalettes[$strSelector . '_' . $varValue]); if ($blnActive) { $strSubpalette = $strSelector . '_' . $varValue; $arrSubPaletteFields = FormHelper::getPaletteFields($this->strTable, $this->dca['subpalettes'][$strSubpalette]); } // remove concatenated type selector sibling subpalette fields that are not active foreach ($arrSubpalettes as $strSubSiblingPalette => $strSubSiblingFields) { // do not remove active concatenated type selector fields if ($blnActive && $strSubSiblingPalette === $strSubpalette) { continue; } $arrFields = array_diff($arrFields, FormHelper::getPaletteFields($this->strTable, $this->dca['subpalettes'][$strSubSiblingPalette])); } } } } return array($blnActive, $strSubpalette, $arrFields, $arrSubPaletteFields, $blnAutoSubmit, $blnToggleSubpalette); }
public function getSubPaletteFields(\DataContainer $arrDca) { $strTable = $arrDca->activeRecord->formHybridDataContainer; $arrSubPalettes = array(); $arrSubPaletteFields = array(); $arrFields = array(); \Controller::loadDataContainer($strTable); $arrSubPalettes = $GLOBALS['TL_DCA'][$strTable]['subpalettes']; if (empty($arrSubPalettes)) { return; } foreach ($arrSubPalettes as $strName => $strPalette) { $arrSubPaletteFields = \HeimrichHannot\FormHybrid\FormHelper::getPaletteFields($strTable, $arrSubPalettes[$strName]); if (empty($arrSubPaletteFields)) { return; } $arrFields = array_merge($arrFields, $arrSubPaletteFields); } return $arrFields; }