/** * Render the context settings field for a certain table * * @param array $params Array of record information * - table - table name * - row - array with database row data * @param t3lib_TCEforms $fobj * @return string */ public function renderRecordSettingsField($params, $fobj) { global $TCA; $table = $params['table']; $fobj->addStyleSheet('tx_contexts_bestyles', t3lib_extMgm::extRelPath('contexts') . 'Resources/Public/StyleSheet/be.css'); $contexts = new Tx_Contexts_Context_Container(); $contexts->initAll(); $namePre = str_replace('[' . $params['field'] . '_', '[' . $params['field'] . '][', $params['itemFormElName']); $settings = $params['fieldConf']['config']['settings']; $content = '<table class="tx_contexts_table_settings typo3-dblist" style="width: auto; min-width:50%">' . '<tbody>' . '<tr class="t3-row-header">' . '<td></td>' . '<td class="tx_contexts_context">' . $fobj->sL('LLL:' . Tx_Contexts_Api_Configuration::LANG_FILE . ':tx_contexts_contexts') . '</td>'; foreach ($settings as $settingName => $config) { $content .= '<td class="tx_contexts_setting">' . $fobj->sL($config['label']) . '</td>'; } $content .= '</tr>'; $uid = (int) $params['row']['uid']; $visibleContexts = 0; foreach ($contexts as $context) { if ($context->getDisabled() || $context->getHideInBackend()) { continue; } /* @var $context Tx_Contexts_Context_Abstract */ ++$visibleContexts; $contSettings = ''; $bHasSetting = false; foreach ($settings as $settingName => $config) { $setting = $uid ? $context->getSetting($table, $settingName, $uid, $params['row']) : null; $bHasSetting = $bHasSetting || (bool) $setting; $contSettings .= '<td class="tx_contexts_setting">' . '<select name="' . $namePre . '[' . $context->getUid() . '][' . $settingName . ']">' . '<option value="">n/a</option>' . '<option value="1"' . ($setting && $setting->getEnabled() ? ' selected="selected"' : '') . '>Yes</option>' . '<option value="0"' . ($setting && !$setting->getEnabled() ? ' selected="selected"' : '') . '>No</option>' . '</select></td>'; } list($icon, $title) = $this->getRecordPreview($context, $uid); $content .= '<tr class="db_list_normal">' . '<td class="tx_contexts_context col-icon"">' . $icon . '</td>' . '<td class="tx_contexts_context">' . '<span class="context-' . ($bHasSetting ? 'active' : 'inactive') . '">' . $title . '</span>' . '</td>' . $contSettings . '</tr>'; } if ($visibleContexts == 0) { $content .= '<tr>' . '<td colspan="4" style="text-align: center">' . $fobj->sL('LLL:' . Tx_Contexts_Api_Configuration::LANG_FILE . ':no_contexts') . '</td>' . '</tr>'; } $content .= '</tbody></table>'; return $content; }
/** * Render the context settings field for a certain table * * @param array $params Array of record information * - table - table name * - row - array with database row data * @param t3lib_TCEforms $fobj * @return string */ public function renderRecordSettingsField($params, $fobj) { global $TCA; $table = $params['table']; $fobj->addStyleSheet('tx_contexts_bestyles', t3lib_extMgm::extRelPath('contexts') . 'Resources/Public/StyleSheet/be.css'); $contexts = new Tx_Contexts_Context_Container(); $contexts->initAll(); $namePre = str_replace('[' . $params['field'] . '_', '[' . $params['field'] . '][', $params['itemFormElName']); $settings = $params['fieldConf']['config']['settings']; $content = ''; //Check for the current workspace. If it's not LIVE, throw info message and disable context editing further down $currentWorkspace = $GLOBALS['BE_USER']->workspace; if ($currentWorkspace != 0) { $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', 'Contexts are read-only in this workspace. Switch to LIVE version to change them.', '', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, FALSE); $content .= $message->render(); } $content .= '<table class="tx_contexts_table_settings typo3-dblist" style="width: auto; min-width:50%">' . '<tbody>' . '<tr class="t3-row-header">' . '<td></td>' . '<td class="tx_contexts_context">' . $fobj->sL('LLL:' . Tx_Contexts_Api_Configuration::LANG_FILE . ':tx_contexts_contexts') . '</td>'; foreach ($settings as $settingName => $config) { $content .= '<td class="tx_contexts_setting">' . $fobj->sL($config['label']) . '</td>'; } $content .= '</tr>'; $uid = (int) $params['row']['uid']; $row = $params['row']; //Is this a Workspace Overlay? If so, load original record for plain info view if ($currentWorkspace != 0 && $params['row']['t3ver_oid'] != 0) { $uid = (int) $params['row']['t3ver_oid']; $row = BackendUtility::getLiveVersionOfRecord($table, $params['row']['uid']); } $visibleContexts = 0; foreach ($contexts as $context) { if ($context->getDisabled() || $context->getHideInBackend()) { continue; } /* @var $context Tx_Contexts_Context_Abstract */ ++$visibleContexts; $contSettings = ''; $bHasSetting = false; foreach ($settings as $settingName => $config) { $setting = $uid ? $context->getSetting($table, $settingName, $uid, $row) : null; $bHasSetting = $bHasSetting || (bool) $setting; if ($currentWorkspace != 0) { $contSettings .= '<td class="tx_contexts_setting">'; if ($setting && $setting->getEnabled()) { $contSettings .= '<span class="context-active">Yes</span>'; } else { if ($setting && !$setting->getEnabled()) { $contSettings .= '<span class="context-active">No</span>'; } else { $contSettings .= 'n/a'; } } $contSettings .= '</td>'; } else { $contSettings .= '<td class="tx_contexts_setting">' . '<select name="' . $namePre . '[' . $context->getUid() . '][' . $settingName . ']">' . '<option value="">n/a</option>' . '<option value="1"' . ($setting && $setting->getEnabled() ? ' selected="selected"' : '') . '>Yes</option>' . '<option value="0"' . ($setting && !$setting->getEnabled() ? ' selected="selected"' : '') . '>No</option>' . '</select></td>'; } } list($icon, $title) = $this->getRecordPreview($context, $uid); $content .= '<tr class="db_list_normal">' . '<td class="tx_contexts_context col-icon"">' . $icon . '</td>' . '<td class="tx_contexts_context">' . '<span class="context-' . ($bHasSetting ? 'active' : 'inactive') . '">' . $title . '</span>' . '</td>' . $contSettings . '</tr>'; } if ($visibleContexts == 0) { $content .= '<tr>' . '<td colspan="4" style="text-align: center">' . $fobj->sL('LLL:' . Tx_Contexts_Api_Configuration::LANG_FILE . ':no_contexts') . '</td>' . '</tr>'; } $content .= '</tbody></table>'; return $content; }