Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Created May 8, 2013 22:08
Show Gist options
  • Save betweenbrain/5544043 to your computer and use it in GitHub Desktop.
Save betweenbrain/5544043 to your computer and use it in GitHub Desktop.
User configurable Joomla! 1.5 module select element
class JElementFoo extends JElement {
var $_name = 'foo';
function fetchElement($name, $value, &$node, $control_name) {
$cid = JRequest::getVar('cid');
$db = JFactory::getDBO();
$options = array();
$query = ' SELECT params' .
' FROM #__modules' .
' WHERE id = ' . $cid[0] . '';
$db->setQuery($query);
$params = $db->loadResult();
preg_match('/configuration=([^\n]*)/', $params, $matches);
$ids = explode(';', rtrim($matches[1], ';'));
foreach ($ids as $id) {
$pair = explode('|', $id);
$options[] = JHtml::_('select.option', $pair[0], $pair[1]);
}
return JHTML::_('select.genericlist', $options, '' . $control_name . '[' . $name . ']', '', 'value', 'text', $value, $control_name . $name);
}
}
@betweenbrain
Copy link
Author

Uses a syntax of:

foo|bar;

For each element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment