0

We want to move all field groups to the first content tab on the backend and assign individual classes to every field group. Therefore, we've already ignored the fieldsets to avoid the creation of the tabs:

$this->ignore_fieldsets[] = 'fields-1';

Now, we're calling each fieldgroup individually and add a class:

        <div class="span9 fieldset-class-1">
        <div class="fieldset-title-container">
            <h3><?php echo $fieldset['fields-1']->label; ?></h3>
            <h4><?php echo $fieldset['fields-1']->description; ?></h4>
        </div>  
            <?php echo $this->form->renderFieldset('fields-1'); ?>    
        </div>

The fieldsets are perfectly shown on the backend but the fieldset title and description is not showing. Any ideas how this can be achieved?

This is the full code of /html/com_content/article/edit.php:

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_content
 *
 * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\Registry\Registry;

// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');

JHtml::_('behavior.formvalidator');
JHtml::_('behavior.keepalive');
JHtml::_('formbehavior.chosen', '#jform_catid', null, array('disable_search_threshold' => 0 ));
JHtml::_('formbehavior.chosen', '#jform_tags', null, array('placeholder_text_multiple' => JText::_('JGLOBAL_TYPE_OR_SELECT_SOME_TAGS')));
JHtml::_('formbehavior.chosen', 'select');

$this->configFieldsets  = array('editorConfig');
$this->hiddenFieldsets  = array('basic-limited');
$this->ignore_fieldsets = array('jmetadata', 'item_associations');

// In order to avoid the creation of tabs, we're ignoring here the 3 field sets.
$this->ignore_fieldsets[] = 'fields-1';
$this->ignore_fieldsets[] = 'fields-2';
$this->ignore_fieldsets[] = 'fields-3';


// Create shortcut to parameters.
$params = clone $this->state->get('params');
$params->merge(new Registry($this->item->attribs));

$app = JFactory::getApplication();
$input = $app->input;

$assoc = JLanguageAssociations::isEnabled();

JFactory::getDocument()->addScriptDeclaration('
    Joomla.submitbutton = function(task)
    {
        if (task == "article.cancel" || document.formvalidator.isValid(document.getElementById("item-form")))
        {
            jQuery("#permissions-sliders select").attr("disabled", "disabled");
            ' . $this->form->getField('articletext')->save() . '
            Joomla.submitform(task, document.getElementById("item-form"));

            // @deprecated 4.0  The following js is not needed since 3.7.0.
            if (task !== "article.apply")
            {
                window.parent.jQuery("#articleEdit' . (int) $this->item->id . 'Modal").modal("hide");
            }
        }
    };
');

// In case of modal
$isModal = $input->get('layout') == 'modal' ? true : false;
$layout  = $isModal ? 'modal' : 'edit';
$tmpl    = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=component' : '';
?>

<form action="<?php echo JRoute::_('index.php?option=com_content&layout=' . $layout . $tmpl . '&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="item-form" class="form-validate">

    <?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?>

    <div class="form-horizontal">
        <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_CONTENT_ARTICLE_CONTENT')); ?>
        <div class="row-fluid">
            <div class="span9">
                <fieldset class="adminform">

                    <?php echo $this->form->getInput('articletext'); ?>
                </fieldset>
            </div>
            <div class="span3">
                <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
            </div>
        </div>





    <?php /* -------- display all fields manually, however the title of the fieldsets are still missing   */?>    

      <div class="row-fluid form-horizontal-desktop">

        <div class="span9 fieldset-class-1">
            <div class="fieldset-title-container">
                <h3><?php echo $fieldset['fields-1']->label; ?></h3>
                <h4><?php echo $fieldset['fields-1']->description; ?></h4>
            </div>  
                <?php echo $this->form->renderFieldset('fields-1'); ?>    
        </div>


        <div class="span9 fieldset-class-2">
            <div class="fieldset-title-container">
                <h3><?php echo $fieldset['fields-2']->label; ?></h3>
                <h4><?php echo $fieldset['fields-2']->description; ?></h4>
            </div>  
                <?php echo $this->form->renderFieldset('fields-2'); ?>    
        </div>        


        <div class="span9 fieldset-class-2">
            <div class="fieldset-title-container">
                <h3><?php echo $fieldset['fields-2']->label; ?></h3>
                <h4><?php echo $fieldset['fields-2']->description; ?></h4>
            </div>  
                <?php echo $this->form->renderFieldset('fields-2'); ?>    
        </div>

    </div>      








        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php // Do not show the images and links options if the edit form is configured not to. ?>
        <?php if ($params->get('show_urls_images_backend') == 1) : ?>
            <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'images', JText::_('COM_CONTENT_FIELDSET_URLS_AND_IMAGES')); ?>
            <div class="row-fluid form-horizontal-desktop">
                <div class="span6">
                    <?php echo $this->form->renderField('images'); ?>
                    <?php foreach ($this->form->getGroup('images') as $field) : ?>
                        <?php echo $field->renderField(); ?>
                    <?php endforeach; ?>
                </div>
                <div class="span6">
                    <?php foreach ($this->form->getGroup('urls') as $field) : ?>
                        <?php echo $field->renderField(); ?>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php echo JHtml::_('bootstrap.endTab'); ?>
        <?php endif; ?>

        <?php $this->show_options = $params->get('show_article_options', 1); ?>
        <?php echo JLayoutHelper::render('joomla.edit.params', $this); ?>

        <?php // Do not show the publishing options if the edit form is configured not to. ?>
        <?php if ($params->get('show_publishing_options', 1) == 1) : ?>
            <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('COM_CONTENT_FIELDSET_PUBLISHING')); ?>
            <div class="row-fluid form-horizontal-desktop">
                <div class="span6">
                    <?php echo JLayoutHelper::render('joomla.edit.publishingdata', $this); ?>
                </div>
                <div class="span6">
                    <?php echo JLayoutHelper::render('joomla.edit.metadata', $this); ?>
                </div>
            </div>
            <?php echo JHtml::_('bootstrap.endTab'); ?>
        <?php endif; ?>


        <?php if ( ! $isModal && $assoc) : ?>
            <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'associations', JText::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
            <?php echo $this->loadTemplate('associations'); ?>
            <?php echo JHtml::_('bootstrap.endTab'); ?>
        <?php elseif ($isModal && $assoc) : ?>
            <div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div>
        <?php endif; ?>

        <?php if ($this->canDo->get('core.admin')) : ?>
            <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'editor', JText::_('COM_CONTENT_SLIDER_EDITOR_CONFIG')); ?>
            <?php echo $this->form->renderFieldset('editorConfig'); ?>
            <?php echo JHtml::_('bootstrap.endTab'); ?>
        <?php endif; ?>

        <?php if ($this->canDo->get('core.admin')) : ?>
            <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'permissions', JText::_('COM_CONTENT_FIELDSET_RULES')); ?>
                <?php echo $this->form->getInput('rules'); ?>
            <?php echo JHtml::_('bootstrap.endTab'); ?>
        <?php endif; ?>

        <?php echo JHtml::_('bootstrap.endTabSet'); ?>

        <input type="hidden" name="task" value="" />
        <input type="hidden" name="return" value="<?php echo $input->getCmd('return'); ?>" />
        <input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
        <?php echo JHtml::_('form.token'); ?>
    </div>
</form>
  • Can you print the $fieldset['fields-1'] object data to screen and show us what you've got? Do you know how to do this? – mickmackusa Dec 13 '19 at 7:36
  • thank you very much for your contribution! No, please advise how this can be done. – Fabian Äuis Gisler Dec 13 '19 at 7:43
  • Perhaps echo json_encode($fieldset['fields-1'], JSON_PRETTY_PRINT); in your view or whack JFactory::getApplication()->enqueueMessage(json_encode($fieldset['fields-1'], JSON_PRETTY_PRINT), 'info'); in the script where you are accessing the variable. I may not be able to help you to solve this issue, but I can try to get some more hints into your question. – mickmackusa Dec 13 '19 at 7:45
  • Can you please provide more of the code around how you are getting or setting the values for $fieldset? Have you considered using getFieldsets and then lopping through each fieldset getting the $fieldset->name and looping through the fields in that fieldset.to get the rest of the information to display? – Irata Dec 13 '19 at 9:39
  • Thank you! We've added the full code of the adapted edit.php. The fields are perfectly shown on the first tab of the backend with individual css classes but the field group (fieldset) title and description of each group is still missing. – Fabian Äuis Gisler Dec 13 '19 at 10:29
1

If I'm understanding you right, I think you want to have in your form definition xml file

<fieldset name="fields-1" label="label-1" description="desc 1"> ...

Then in your layout file do

$fieldset = $this->form->getFieldsets();

and then you can do

echo $fieldset['fields-1']->label;    // outputs "label-1"
echo $fieldset['fields-1']->description; 

Have I understood you right?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.