diff --git a/administrator/components/com_fields/models/fields/fieldlayout.php b/administrator/components/com_fields/models/fields/fieldlayout.php new file mode 100644 index 0000000000000..5a0e49e18baa0 --- /dev/null +++ b/administrator/components/com_fields/models/fields/fieldlayout.php @@ -0,0 +1,165 @@ +form->getValue('context'))[0]; + + if ($extension) + { + // Get the database object and a new query object. + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + + // Build the query. + $query->select('element, name') + ->from('#__extensions') + ->where('client_id = 0') + ->where('type = ' . $db->quote('template')) + ->where('enabled = 1'); + + // Set the query and load the templates. + $db->setQuery($query); + $templates = $db->loadObjectList('element'); + + // Build the search paths for component layouts. + $component_path = JPath::clean(JPATH_SITE . '/components/' . $extension . '/layouts/field'); + + // Prepare array of component layouts + $component_layouts = array(); + + // Prepare the grouped list + $groups = array(); + + // Add "Use Default" + $groups[]['items'][] = JHtml::_('select.option', '', JText::_('JOPTION_USE_DEFAULT')); + + // Add the layout options from the component path. + if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\.php$', false, true))) + { + // Create the group for the component + $groups['_'] = array(); + $groups['_']['id'] = $this->id . '__'; + $groups['_']['text'] = JText::sprintf('JOPTION_FROM_COMPONENT'); + $groups['_']['items'] = array(); + + foreach ($component_layouts as $i => $file) + { + // Add an option to the component group + $value = basename($file, '.php'); + $component_layouts[$i] = $value; + + if ($value === 'render') + { + continue; + } + + $groups['_']['items'][] = JHtml::_('select.option', $value, $value); + } + } + + // Loop on all templates + if ($templates) + { + foreach ($templates as $template) + { + $files = array(); + $template_paths = array( + JPath::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/' . $extension . '/field'), + JPath::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/com_fields/field'), + JPath::clean(JPATH_SITE . '/templates/' . $template->element . '/html/layouts/field'), + ); + + // Add the layout options from the template paths. + foreach ($template_paths as $template_path) + { + if (is_dir($template_path)) + { + $files = array_merge($files, JFolder::files($template_path, '^[^_]*\.php$', false, true)); + } + } + + foreach ($files as $i => $file) + { + $value = basename($file, '.php'); + + // Remove the default "render.php" or layout files that exist in the component folder + if ($value === 'render' || in_array($value, $component_layouts)) + { + unset($files[$i]); + } + } + + if (count($files)) + { + // Create the group for the template + $groups[$template->name] = array(); + $groups[$template->name]['id'] = $this->id . '_' . $template->element; + $groups[$template->name]['text'] = JText::sprintf('JOPTION_FROM_TEMPLATE', $template->name); + $groups[$template->name]['items'] = array(); + + foreach ($files as $file) + { + // Add an option to the template group + $value = basename($file, '.php'); + $groups[$template->name]['items'][] = JHtml::_('select.option', $value, $value); + } + } + } + } + + // Compute attributes for the grouped list + $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; + $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; + + // Prepare HTML code + $html = array(); + + // Compute the current selected values + $selected = array($this->value); + + // Add a grouped list + $html[] = JHtml::_( + 'select.groupedlist', $groups, $this->name, + array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected) + ); + + return implode($html); + } + + return ''; + } +} diff --git a/administrator/components/com_fields/models/forms/field.xml b/administrator/components/com_fields/models/forms/field.xml index 7958234104aaf..e8183ace672c0 100644 --- a/administrator/components/com_fields/models/forms/field.xml +++ b/administrator/components/com_fields/models/forms/field.xml @@ -288,6 +288,13 @@ + + $field)); + $layout = $field->params->get('layout', 'render'); + echo FieldsHelper::render($context, 'field.' . $layout, array('field' => $field)); } if (!$isMail) diff --git a/components/com_fields/layouts/fields/render.php b/components/com_fields/layouts/fields/render.php index 37c4153ed19c0..8db4f278228e8 100644 --- a/components/com_fields/layouts/fields/render.php +++ b/components/com_fields/layouts/fields/render.php @@ -57,8 +57,9 @@ params->get('render_class'); ?> + params->get('layout', 'render'); ?>
- $field)); ?> + $field)); ?>
diff --git a/plugins/content/fields/fields.php b/plugins/content/fields/fields.php index 029c911592292..a13bb8a4bb9c8 100644 --- a/plugins/content/fields/fields.php +++ b/plugins/content/fields/fields.php @@ -116,13 +116,13 @@ private function prepare($string, $context, $item) // $match[0] is the full pattern match, $match[1] is the type (field or fieldgroup) and $match[2] the ID and optional the layout $explode = explode(',', $match[2]); $id = (int) $explode[0]; - $layout = !empty($explode[1]) ? trim($explode[1]) : 'render'; $output = ''; if ($match[1] == 'field' && $id) { if (isset($fieldsById[$id])) { + $layout = !empty($explode[1]) ? trim($explode[1]) : $fieldsById[$id]->params->get('layout', 'render'); $output = FieldsHelper::render( $context, 'field.' . $layout, @@ -148,6 +148,7 @@ private function prepare($string, $context, $item) if ($renderFields) { + $layout = !empty($explode[1]) ? trim($explode[1]) : 'render'; $output = FieldsHelper::render( $context, 'fields.' . $layout,