Skip to content

Commit

Permalink
fixes Fabrik#1073 - joomla 3.2 changes the way bootstrap grouped inpu…
Browse files Browse the repository at this point in the history
…ts need to be rendered
  • Loading branch information
pollen8 committed Nov 13, 2013
1 parent 03ece17 commit 6f05df3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
69 changes: 55 additions & 14 deletions components/com_fabrik/helpers/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1945,36 +1945,34 @@ protected static function propertiesFromArray($properties)
}

/**
* Make a grid of items
* Build array of items for use in grid()
*
* @param array $values Option values
* @param array $labels Option labels
* @param array $selected Selected options
* @param string $name Input name
* @param string $type Checkbox/radio etc
* @param bool $elementBeforeLabel Element before or after the label - deprecated - not used in Joomla 3
* @param int $optionsPerRow Number of suboptions to show per row
* @param array $classes Label classes
* @param bool $buttonGroup Should it be rendered as a bootstrap button group (radio only)
*
* @return string grid
* @return array Grid items
*/

public static function grid($values, $labels, $selected, $name, $type = "checkbox",
$elementBeforeLabel = true, $optionsPerRow = 4, $classes = array(), $buttonGroup = false)
public static function gridItems($values, $labels, $selected, $name, $type = 'checkbox',
$elementBeforeLabel = true, $classes = array(), $buttonGroup = false)
{
$items = array();
$j3 = FabrikWorker::j3();
$version = new JVersion;

if (FabrikWorker::j3())
{
$elementBeforeLabel = true;
}
// Button group rendering seems to have changed in J3.2
$j32ButtonGroup = version_compare($version->RELEASE, 3.2, '>=') && $buttonGroup;

for ($i = 0; $i < count($values); $i++)
{
$item = array();
$thisname = $type === 'checkbox' ? FabrikString::rtrimword($name, '[]') . '[' . $i . ']' : $name;
$label = '<span>' . $labels[$i] . '</span>';
$label = $j32ButtonGroup? $labels[$i] : '<span>' . $labels[$i] . '</span>';

// For values like '1"'
$value = htmlspecialchars($values[$i], ENT_QUOTES);
Expand All @@ -1985,16 +1983,59 @@ public static function grid($values, $labels, $selected, $name, $type = "checkbo
$inputClass .= ' ' . implode(' ', $classes['input']);
}

preg_match('/[\w\s]+/', $name, $id);
$id = $id[0] . '_' . $i;
$chx = '<input type="' . $type . '" class="fabrikinput ' . $inputClass . '" name="' . $thisname . '" value="' . $value . '" ';
$sel = in_array($values[$i], $selected);
$chx .= $j32ButtonGroup ? ' id="' . $id . '"' : '';
$chx .= $sel ? ' checked="checked" />' : ' />';
$labelClass = FabrikWorker::j3() && !$buttonGroup ? $type : '';
$item[] = '<label class="fabrikgrid_' . $value . ' ' . $labelClass . '">';
$item[] = $elementBeforeLabel == '1' ? $chx . $label : $label . $chx;
$item[] = '</label>';

if ($j32ButtonGroup)
{
$item[] = $chx;
$item[] = '<label for="' . $id . '" class="fabrikgrid_' . $value . ' ' . $labelClass . '">' . $label . '</label>';
}
else
{
$item[] = '<label class="fabrikgrid_' . $value . ' ' . $labelClass . '">';
$item[] = $elementBeforeLabel == '1' ? $chx . $label : $label . $chx;
$item[] = '</label>';
}
$items[] = implode("\n", $item);
}

return $items;
}

/**
* Make a grid of items
*
* @param array $values Option values
* @param array $labels Option labels
* @param array $selected Selected options
* @param string $name Input name
* @param string $type Checkbox/radio etc
* @param bool $elementBeforeLabel Element before or after the label - deprecated - not used in Joomla 3
* @param int $optionsPerRow Number of suboptions to show per row
* @param array $classes Label classes
* @param bool $buttonGroup Should it be rendered as a bootstrap button group (radio only)
*
* @return string grid
*/

public static function grid($values, $labels, $selected, $name, $type = 'checkbox',
$elementBeforeLabel = true, $optionsPerRow = 4, $classes = array(), $buttonGroup = false)
{
$items = array();

if (FabrikWorker::j3())
{
$elementBeforeLabel = true;
}

$items = self::gridItems($values, $labels, $selected, $name, $type, $elementBeforeLabel, $classes, $buttonGroup);

$grid = array();
$optionsPerRow = empty($optionsPerRow) ? 4 : $optionsPerRow;
$w = floor(100 / $optionsPerRow);
Expand Down
2 changes: 1 addition & 1 deletion plugins/fabrik_element/yesno/yesno.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function renderListData_pdf($data, $thisRow)
}
else
{
$icon = $j3 ? 'checkmark.png' : '0_8bit.png';
$icon = $j3 ? 'remove.png' : '0_8bit.png';

return FabrikHelperHTML::image($icon, 'list', $this->tmpl, array('alt' => JText::_('JNO')));
}
Expand Down

0 comments on commit 6f05df3

Please sign in to comment.