Skip to content

Commit

Permalink
fix for #319
Browse files Browse the repository at this point in the history
  • Loading branch information
moldcraft committed Mar 6, 2015
1 parent 6b594c0 commit 5bd763f
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 66 deletions.
145 changes: 89 additions & 56 deletions framework/core/components/backend.php
Expand Up @@ -974,78 +974,111 @@ public function render_options($options, $values = array(), $options_data = arra


fw_collect_first_level_options($collected, $options); fw_collect_first_level_options($collected, $options);


ob_start(); if (empty($collected['all'])) {

return false;
if (!empty($collected['tabs'])) {
fw_render_view(fw_get_framework_directory('/views/backend-tabs.php'), array(
'tabs' => &$collected['tabs'],
'values' => &$values,
'options_data' => $options_data,
), false);
} }
unset($collected['tabs']);


if (!empty($collected['boxes'])) { $html = '';
echo '<div class="fw-backend-postboxes metabox-holder">';


foreach ($collected['boxes'] as $id => &$box) { $option = reset($collected['all']);
// prepare attributes
{
$attr = isset($box['attr']) ? $box['attr'] : array();


unset($attr['id']); // do not allow id overwrite, it is sent in first argument of render_box() $collected_type = $option['type'];
} $collected_type_options = array(
$option['id'] => &$option['option']
);


echo $this->render_box( while ($collected_type_options) {
'fw-options-box-'. $id, $option = next($collected['all']);
empty($box['title']) ? ' ' : $box['title'],
$this->render_options($box['options'], $values, $options_data),
array(
'attr' => $attr
)
);
}


echo '</div>'; if ($option) {
} if ($option['type'] === $collected_type) {
unset($collected['boxes']); $collected_type_options[$option['id']] = &$option['option'];
continue;
}
}


if (!empty($collected['groups_and_options'])) { switch ($collected_type) {
foreach ($collected['groups_and_options'] as $id => &$option) { case 'tab':
if (isset($option['options'])) { // group $html .= fw_render_view(fw_get_framework_directory('/views/backend-tabs.php'), array(
// prepare attributes 'tabs' => &$collected_type_options,
{ 'values' => &$values,
$attr = isset($option['attr']) ? $option['attr'] : array(); 'options_data' => $options_data,
));
break;
case 'box':
$html .= '<div class="fw-backend-postboxes metabox-holder">';

foreach ($collected_type_options as $id => &$box) {
// prepare attributes
{
$attr = isset($box['attr']) ? $box['attr'] : array();

unset($attr['id']); // do not allow id overwrite, it is sent in first argument of render_box()
}


$attr['id'] = 'fw-backend-options-group-'. esc_attr($id); $html .= $this->render_box(
'fw-options-box-'. $id,
empty($box['title']) ? ' ' : $box['title'],
$this->render_options($box['options'], $values, $options_data),
array(
'attr' => $attr
)
);
}


if (!isset($attr['class'])) { $html .= '</div>';
$attr['class'] = 'fw-backend-options-group'; break;
} else { case 'group':
$attr['class'] = 'fw-backend-options-group '. $attr['class']; foreach ($collected_type_options as $id => &$group) {
// prepare attributes
{
$attr = isset($group['attr']) ? $group['attr'] : array();

$attr['id'] = 'fw-backend-options-group-' . $id;

if (!isset($attr['class'])) {
$attr['class'] = 'fw-backend-options-group';
} else {
$attr['class'] = 'fw-backend-options-group ' . $attr['class'];
}
} }
}


echo '<div '. fw_attr_to_html($attr) .'>'; $html .= '<div ' . fw_attr_to_html($attr) . '>';
echo $this->render_options($option['options'], $values, $options_data); $html .= $this->render_options($group['options'], $values, $options_data);
echo '</div>'; $html .= '</div>';
} else { // option }
$data = $options_data; break;
case 'option':
foreach ($collected_type_options as $id => &$_option) {
$data = $options_data;

$data['value'] = isset($values[$id]) ? $values[$id] : null;

$html .= $this->render_option(
$id,
$_option,
$data,
$design
);
}
break;
default:
$html .= '<p><em>'. __('Unknown collected type', 'fw') .': '. $collected_type .'</em></p>';
}


$data['value'] = isset($values[$id]) ? $values[$id] : null; unset($collected_type, $collected_type_options);


echo $this->render_option( if ($option) {
$id, $collected_type = $option['type'];
$option, $collected_type_options = array(
$data, $option['id'] => &$option['option']
$design );
); } else {
} $collected_type_options = array();
} }
} }
unset($collected['options']);


return ob_get_clean(); return $html;
} }


/** /**
Expand Down
31 changes: 21 additions & 10 deletions framework/helpers/general.php
Expand Up @@ -627,17 +627,17 @@ function fw_extract_only_options(array $options, &$_recursion_options = array())
* @param array $options * @param array $options
*/ */
function fw_collect_first_level_options(&$collected, &$options) { function fw_collect_first_level_options(&$collected, &$options) {
if (empty($options)) if (empty($options)) {
return; return;
}


if (empty($collected)) { if (empty($collected)) {
$collected['tabs'] = array(); $collected['tabs'] =
$collected['boxes'] = array(); $collected['boxes'] =
$collected['groups'] = array(); $collected['groups'] =

$collected['options'] =
$collected['options'] = array(); $collected['groups_and_options'] =

$collected['all'] = array();
$collected['groups_and_options'] = array();
} }


foreach ($options as $option_id => &$option) { foreach ($options as $option_id => &$option) {
Expand All @@ -653,12 +653,18 @@ function fw_collect_first_level_options(&$collected, &$options) {
break; break;
case 'group': case 'group':
$collected['groups'][$option_id] =& $option; $collected['groups'][$option_id] =& $option;

$collected['groups_and_options'][$option_id] =& $option; $collected['groups_and_options'][$option_id] =& $option;
break; break;
default: default:
trigger_error('Invalid option container type: '. $option['type'], E_USER_WARNING); trigger_error('Invalid option container type: '. $option['type'], E_USER_WARNING);
continue 2;
} }

$collected['all'][ $option['type'] .':~:'. $option_id ] = array(
'type' => $option['type'],
'id' => $option_id,
'option' => &$option,
);
} elseif ( } elseif (
is_int($option_id) is_int($option_id)
&& &&
Expand Down Expand Up @@ -698,8 +704,13 @@ function fw_collect_first_level_options(&$collected, &$options) {
} elseif (isset($option['type'])) { } elseif (isset($option['type'])) {
// simple option, last possible level in options array // simple option, last possible level in options array
$collected['options'][$option_id] =& $option; $collected['options'][$option_id] =& $option;

$collected['groups_and_options'][$option_id] =& $option; $collected['groups_and_options'][$option_id] =& $option;

$collected['all'][ 'option' .':~:'. $option_id ] = array(
'type' => 'option',
'id' => $option_id,
'option' => &$option,
);
} else { } else {
trigger_error('Invalid option: '. $option_id, E_USER_WARNING); trigger_error('Invalid option: '. $option_id, E_USER_WARNING);
} }
Expand Down

0 comments on commit 5bd763f

Please sign in to comment.