2

We want to make the views of our component as res-usable as possible, displaying the data differently, depending on how the view is being used. The components parameters are suitable for the general display, but which display mode to use would depend on the how the menu option to the view is set up.

Additionally, we have many 3rd party data providers that are optionally installed, most of which can be configured, engaged/disengaged, and variable API parameters specified.

How is this done, as I've seen accomplished with extensions like menu modules and templates?

4

You could use menu parameters. They are similar to the component parameters but can be set up different for each menu item. Menu parameters can be defined in your view's template XML file (e.g. /components/com_yourcomponent/views/yourview/tmpl/default.xml)

Tutorial: https://docs.joomla.org/J3.x:Developing_a_MVC_Component/Adding_a_variable_request_in_the_menu_type

2

A view can have several layouts in the tmpl view directoy, and layouts can be overriden at template level.

  • True, perhaps a poor example of our motivation - there's actually considerable configuration for 3rd party data providers in the component, and whether or not to use them is another aspect of the menu item setup. – GDP Dec 12 '14 at 14:59
2

Turns out menu items are processed with a Content Plugin as well, so this can add custom options using a specified XML form:

// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
class plgContentMyPlugin extends JPlugin {
    function onContentPrepareForm($form, $data) {
        $option = JFactory::getApplication()->input->get('option');
        if($option == 'com_menus'){
            if(is_object($data)) return;
            JForm::addFormPath(__DIR__ . '/forms'); // Path to XML
            $form->loadFile('my_menuoptions', false);
            return true;
        }
    }
}

** Form XML of custom menu Options **
plugins\content\myPlugin\forms\my_menuoptions.xml
<?xml version="1.0" encoding="utf-8"?>
  <form>
   <fields name="params">
       <fieldset name="MyMenuOptions" label="My Options">
            <field name="custom1" type="text" size="10" label="My Custom Field 1"class="inputbox" labelclass="control-label" />
            <field name="custom2" type="radio" class="btn-group" default="1" label="My Custom Field 2">
                <option value="1">One</option>
                <option value="2">Two</option>
            </field>
        </fieldset>
  </fields>
</form>

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.