Method to get the field input for module layouts.
{
$clientId = $this->element['client_id'];
if (is_null($clientId) && $this->form instanceof
JForm)
{
$clientId = $this->form->getValue('client_id');
}
$clientId = (int) $clientId;
$client = JApplicationHelper::getClientInfo($clientId);
$module = (string) $this->element['module'];
if (empty($module) && ($this->form instanceof JForm))
{
$module = $this->form->getValue('module');
}
$module = preg_replace('#\W#', '', $module);
$template = (string) $this->element['template'];
$template = preg_replace('#\W#', '', $template);
if ($this->form instanceof JForm)
{
$template_style_id = $this->form->getValue('template_style_id');
}
$template_style_id = preg_replace('#\W#', '', $template_style_id);
if ($module && $client)
{
$lang->load($module . '.sys', $client->path, null, false, false)
|| $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, false)
|| $lang->load($module . '.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load($module . '.sys', $client->path . '/modules/' . $module, $lang->getDefault(), false, false);
$query = $db->getQuery(true);
$query->select('element, name')
->from('#__extensions as e')
->where('e.client_id = ' . (int) $clientId)
->where('e.type = ' . $db->quote('template'))
->where('e.enabled = 1');
if ($template)
{
$query->where('e.element = ' . $db->quote($template));
}
if ($template_style_id)
{
$query->join('LEFT', '#__template_styles as s on s.template=e.element')
->where('s.id=' . (int) $template_style_id);
}
$db->setQuery($query);
$templates = $db->loadObjectList('element');
$module_path =
JPath::clean($client->path .
'/modules/' . $module .
'/tmpl');
$module_layouts = array();
$groups = array();
if (is_dir($module_path) && ($module_layouts =
JFolder::files($module_path,
'^[^_]*\.php$')))
{
$groups['_'] = array();
$groups['_']['id'] = $this->id . '__';
$groups['_']['items'] = array();
foreach ($module_layouts as $file)
{
$value = basename($file,
'.php');
$text = $lang->hasKey($key = strtoupper($module .
'_LAYOUT_' .
$value)) ?
JText::_($key) : $value;
$groups['_']['items'][] = JHtml::_('select.option', '_:' . $value, $text);
}
}
if ($templates)
{
foreach ($templates as $template)
{
$lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false)
|| $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false)
|| $lang->load(
'tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(),
false, false
);
$template_path =
JPath::clean($client->path .
'/templates/' . $template->element .
'/html/' . $module);
if (is_dir($template_path) && ($files =
JFolder::files($template_path,
'^[^_]*\.php$')))
{
foreach ($files as $i => $file)
{
if (in_array($file, $module_layouts))
{
unset($files[$i]);
}
}
if (count($files))
{
$groups[$template->element] = array();
$groups[$template->element]['id'] = $this->id . '_' . $template->element;
$groups[$template->element][
'text'] =
JText::sprintf(
'JOPTION_FROM_TEMPLATE', $template->name);
$groups[$template->element]['items'] = array();
foreach ($files as $file)
{
$value = basename($file,
'.php');
$text = $lang->hasKey($key = strtoupper(
'TPL_' . $template->element .
'_' . $module .
'_LAYOUT_' .
$value))
$groups[$template->element][
'items'][] = JHtml::_(
'select.option', $template->element .
':' .
$value, $text);
}
}
}
}
}
$attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$html = array();
$selected = array($this->value);
$html[] = JHtml::_(
'select.groupedlist', $groups, $this->name,
array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected)
);
return implode($html);
}
else
{
return '';
}
}