Chimera.Zen
Chimera.Zen

Reputation: 1180

Multiple edit forms for custom joomla component

Following the docs on Joomla for creating a custom component, and searching through the forums, I've created several admin views with menu links, etc and all work fine. The break comes when I try to edit an item in any view. The edit page is always the default HelloWorld messages form. Just for S&G I did a find and replace on all helloworld. Nothing broke and the forms still redirected to the default messages form. This leads me to believe I need to include an &task= or something to the form tag so that it knows where to redirect. Am I on the right track or am I so derailed that the caboose is leading?

Cheers!

P.S. I noticed that when I choose an element to edit in views/elements.php it does have an &task=element.edit associated with it now, but still seems to be calling the default HelloWorld.messages

Sorry for poor indentation. It didn't copy over well

admin/views/elements/tmpl/default.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_chimera
 * @author      Chimera.Zen <[email protected]>
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @version         v1.0.5
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
?>
 <form action="index.php?option=com_chimera&view=elements" method="post" id="adminForm" name="adminForm">
  <table class="table table-striped table-hover">
    <thead>
    <tr>
        <th width="1%"><?php echo JText::_('COM_CHIMERA_NUM'); ?></th>
        <th width="2%">
            <?php echo JHtml::_('grid.checkall'); ?>
        </th>
        <th width="10%">
            <?php echo JText::_('COM_CHIMERA_ELEMENT_NAME') ;?>
        </th>
        <th width="10%">
            <?php echo JText::_('COM_CHIMERA_ELEMENT_GROUP') ;?>
        </th>
        <th width="50%">
            <?php echo JText::_('COM_CHIMERA_ELEMENT_ATTRIBUTES') ;?>
        </th>
        <th width="5%">
            <?php echo JText::_('COM_CHIMERA_PUBLISHED'); ?>
        </th>
        <th width="2%">
            <?php echo JText::_('COM_CHIMERA_ID'); ?>
        </th>
    </tr>
    </thead>
    <tbody>
        <?php if (!empty($this->items)) : ?>
            <?php foreach ($this->items as $i => $row) :
                $link = JRoute::_('index.php?option=com_chimera&task=element.edit&id=' . $row->id);
            ?>
                <tr>
                    <td><?php echo $this->pagination->getRowOffset($i); ?></td>
                    <td>
                        <?php echo JHtml::_('grid.id', $i, $row->id); ?>
                    </td>
                    <td>
                        <a href="<?php echo $link; ?>" title="<?php echo JText::_('COM_CHIMERA_EDIT_ELEMENT'); ?>">
                            <?php echo $row->element; ?>
                        </a>
                    </td>
                    <td>
                            <?php echo $row->element_group; ?>
                    </td>
                    <td> <?php
            $attributes = '<ul>';
            foreach($row->attributes as $attribute){
              $href = JRoute::_('index.php?option=com_chimera&view=attributes#'.$attribute["name"]);
              $attributes .= '<li><a href="'.$href.'">'.$attribute["name"];
              if($attribute["global"] == "1"){
                $attributes .= '<i class="global fa fa-globe" aria-hidden="true" title="Global Attribute"></i>';
              }
              $attributes .= '</a></li>';
            }
            $attributes .= '</ul>';
            echo $attributes;?>
                    </td>
                    <td align="center">
                        <?php echo JHtml::_('jgrid.published', $row->published, $i, 'elements.', true, 'cb'); ?>
                    </td>
                    <td align="center">
                        <?php echo $row->id; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="5">
                <?php echo $this->pagination->getListFooter(); ?>
            </td>
        </tr>
    </tfoot>
</table>
<input type="hidden" name="task" value=""/>
<input type="hidden" name="boxchecked" value="0"/>
<?php echo JHtml::_('form.token'); ?>

admin/views/element/tmpl/edit.php

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

// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.formvalidation');
?>
<form action="<?php echo JRoute::_('index.php?option=com_chimera&layout=edit&id=' . (int) $this->item->id); ?>"
    method="post" name="adminForm" id="adminForm" class="form-validate">
    <div class="form-horizontal">
        <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', JText::_('COM_CHIMERA_CHIMERA_DETAILS')); ?>
        <div class="row-fluid">
            <div class="span9">
          <div>
                <?php
                echo $this->form->renderFieldset('details');
                ?>
        </div>
                <div id="image">
                <?php echo $this->form->renderFieldset('params'); ?>
                </div>
            </div>
            <div class="span3">
                <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'accesscontrol', JText::_('COM_CHIMERA_FIELDSET_RULES')); ?>
        <div class="row-fluid form-horizontal-desktop">
            <div class="span12">
                <?php echo $this->form->renderFieldset('accesscontrol'); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.endTabSet'); ?>
    </div>
    <input type="hidden" name="task" value="element.edit" />
    <?php echo JHtml::_('form.token'); ?>
</form>

admin/models/element.php

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

// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.formvalidation');
?>
<form action="<?php echo JRoute::_('index.php?option=com_chimera&layout=edit&id=' . (int) $this->item->id); ?>"
    method="post" name="adminForm" id="adminForm" class="form-validate">
    <div class="form-horizontal">
        <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', JText::_('COM_CHIMERA_CHIMERA_DETAILS')); ?>
        <div class="row-fluid">
            <div class="span9">
          <div>
                <?php
                echo $this->form->renderFieldset('details');
                ?>
        </div>
                <div id="image">
                <?php echo $this->form->renderFieldset('params'); ?>
                </div>
            </div>
            <div class="span3">
                <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'accesscontrol', JText::_('COM_CHIMERA_FIELDSET_RULES')); ?>
        <div class="row-fluid form-horizontal-desktop">
            <div class="span12">
                <?php echo $this->form->renderFieldset('accesscontrol'); ?>
            </div>
        </div>
        <?php echo JHtml::_('bootstrap.endTab'); ?>

        <?php echo JHtml::_('bootstrap.endTabSet'); ?>
    </div>
    <input type="hidden" name="task" value="element.edit" />
    <?php echo JHtml::_('form.token'); ?>
</form>

admin/tables/element.php

<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_chimera
 *
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
// No direct access
defined('_JEXEC') or die('Restricted access');

/**
 * Hello Table class
 *
 * @since  0.0.1
 */
class ChimeraTableElement extends JTable
{
    /**
     * Constructor
     *
     * @param   JDatabaseDriver  &$db  A database connector object
     */
    function __construct(&$db)
    {
        parent::__construct('#__html_attributes', 'id', $db);
    }
    /**
     * Overloaded bind function
     *
     * @param       array           named array
     * @return      null|string     null is operation was satisfactory, otherwise returns an error
     * @see JTable:bind
     * @since 1.5
     */
    public function bind($array, $ignore = '')
    {
        if (isset($array['params']) && is_array($array['params']))
        {
            // Convert the params field to a string.
            $parameter = new JRegistry;
            $parameter->loadArray($array['params']);
            $array['params'] = (string)$parameter;
        }

        // Bind the rules.
        if (isset($array['rules']) && is_array($array['rules']))
        {
            $rules = new JAccessRules($array['rules']);
            $this->setRules($rules);
        }

        return parent::bind($array, $ignore);
    }

    /**
     * Overloaded load function
     *
     * @param       int $pk primary key
     * @param       boolean $reset reset data
     * @return      boolean
     * @see JTable:load
     */
    public function load($pk = null, $reset = true)
    {
        if (parent::load($pk, $reset))
        {
            // Convert the params field to a registry.
            $params = new JRegistry;
            $params->loadString($this->params, 'JSON');

            $this->params = $params;
            return true;
        }
        else
        {
            return false;
        }
    }
    /**
     * Method to compute the default name of the asset.
     * The default name is in the form `table_name.id`
     * where id is the value of the primary key of the table.
     *
     * @return  string
     * @since   2.5
     */
    protected function _getAssetName()
    {
        $k = $this->_tbl_key;
        return 'com_chimera.element.'.(int) $this->$k;
    }
    /**
     * Method to return the title to use for the asset table.
     *
     * @return  string
     * @since   2.5
     */
    protected function _getAssetTitle()
    {
        return $this->element;
    }
    /**
     * Method to get the asset-parent-id of the item
     *
     * @return  int
     */
    protected function _getAssetParentId(JTable $table = NULL, $id = NULL)
    {
        // We will retrieve the parent-asset from the Asset-table
        $assetParent = JTable::getInstance('Asset');
        // Default: if no asset-parent can be found we take the global asset
        $assetParentId = $assetParent->getRootId();

        // Find the parent-asset
        if (($this->catid)&& !empty($this->catid))
        {
            // The item has a category as asset-parent
            $assetParent->loadByName('com_chimera.category.' . (int) $this->catid);
        }
        else
        {
            // The item has the component as asset-parent
            $assetParent->loadByName('com_chimera');
        }

        // Return the found asset-parent-id
        if ($assetParent->id)
        {
            $assetParentId=$assetParent->id;
        }
        return $assetParentId;
    }
}

Upvotes: 1

Views: 732

Answers (1)

Chimera.Zen
Chimera.Zen

Reputation: 1180

After much searching, I found this thread JForm::getInstance could not load file that answered my problem.

Long story short: A broken XML file.

Upvotes: 1

Related Questions