Skip to content

Commit

Permalink
TYPOC-93: read flat setting values from record, not from settings table
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Weiske committed Jul 10, 2015
1 parent 5dde307 commit f3f12af
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
29 changes: 25 additions & 4 deletions Classes/Context/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,31 @@ protected function getConfValue(
* @param string $table Database table name
* @param string $setting Setting name
* @param string $uid Record UID
* @param array $arRow Database row for the given UID.
* Useful for flat settings.
*
* @return Tx_Contexts_Context_Setting|null
* @return Tx_Contexts_Context_Setting|null NULL when not enabled
* and not disabled
*/
final public function getSetting($table, $setting, $uid)
final public function getSetting($table, $setting, $uid, $arRow = null)
{
$settings = $this->getSettings($table, $uid);
if ($arRow !== null) {
//if it's a flat column, use the settings directly from the
// database row instead of relying on the tx_contexts_settings
// table
$arFlatColumns = Tx_Contexts_Api_Configuration::getFlatColumns(
$table, $setting
);
if (isset($arRow[$arFlatColumns[0]])
&& isset($arRow[$arFlatColumns[1]])
) {
return Tx_Contexts_Context_Setting::fromFlatData(
$this, $table, $setting, $arFlatColumns, $arRow
);
}
}

$settings = $this->getSettings($table, $uid, $arRow);

return array_key_exists($setting, $settings)
? $settings[$setting]
Expand All @@ -194,7 +213,9 @@ final public function getSetting($table, $setting, $uid)
* @param string $table Database table
* @param int $uid Record UID
*
* @return array
* @return array Array of settings
* Key is the context column name (e.g. "tx_contexts_nav")
* Value is a Tx_Contexts_Context_Setting object
*/
final public function getSettings($table, $uid)
{
Expand Down
32 changes: 32 additions & 0 deletions Classes/Context/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ public function __construct(Tx_Contexts_Context_Abstract $context, array $row)
$this->enabled = $row['enabled'] ? true : false;
}

/**
* Create a context settings object from flat data
*
* @return Tx_Contexts_Context_Setting|null NULL when not enabled/disabled
*/
public static function fromFlatData(
Tx_Contexts_Context_Abstract $context,
$table, $setting, $arFlatColumns, $arRow
) {
$bDisabled = strpos(
',' . $arRow[$arFlatColumns[0]] . ',',
',' . $context->getUid() . ','
) !== false;
$bEnabled = strpos(
',' . $arRow[$arFlatColumns[1]] . ',',
',' . $context->getUid() . ','
) !== false;

if (!$bEnabled && !$bDisabled) {
return null;
}

$arDummyRow = array(
'uid' => null,
'name' => $setting,
'foreign_table' => $table,
'foreign_uid' => null,
'enabled' => $bEnabled
);
return new self($context, $arDummyRow);
}

public function isDefaultSetting()
{
return !$this->uid;
Expand Down
6 changes: 4 additions & 2 deletions Classes/Service/Tca.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Tx_Contexts_Service_Tca
/**
* Render the context settings field for a certain table
*
* @param array $params
* @param array $params Array of record information
* - table - table name
* - row - array with database row data
* @param t3lib_TCEforms $fobj
* @return string
*/
Expand Down Expand Up @@ -78,7 +80,7 @@ public function renderRecordSettingsField($params, $fobj)
$contSettings = '';
$bHasSetting = false;
foreach ($settings as $settingName => $config) {
$setting = $uid ? $context->getSetting($table, $settingName, $uid) : null;
$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 . ']">'
Expand Down

0 comments on commit f3f12af

Please sign in to comment.