Skip to content
This repository was archived by the owner on Aug 31, 2025. It is now read-only.

Model Header

Daniele Rosario edited this page Dec 19, 2019 · 1 revision

Model Header

Works like the Searchable Header field but instead of hard-coding the options it reads them from a FOF DataModel class.

The additional attributes are:

You can set the following attributes on top of those of the Searchable header field type's:

  • model The name of the Model class to use. You can use one of the following notations

    • A plain name e.g. Items to load the Items model class from your component's current namespace
    • A dotted component.name notation e.g. com_example.Items to load the Items model class from the com_example component In both cases FOF will go through the component's Container to get the Factory and ask it to instantiate the model name you specified.
  • key_field The name of the field in the model's results which is used as the key value of the drop-down

  • value_field The name of the field in the model's results which is used as the label of the drop-down

  • translate Should the value field's value be passed through JText::_() before being displayed?

  • apply_access Should we respect the view access level, if an access field is present in the model

  • with A comma-separated list of relations to eager load. If it's not specified the model's default will be used. You can set an empty attribute to prevent eager loading of relations.

  • none The placeholder to be shown if the value is not found in the data returned by the model. This placeholder goes through JText, so you can use a language string if you like.

  • format See the Text Field

  • show_link See the Text Field

  • url See the Text Field

In order to filter the model you can specify <state> sub-elements in the field's definition:

<state key="state_key">value</state>

Where state_key is the key of a state variable and value is its value. For instance, you could have something like:

<state key="foobar_category_id">123</state>

A full example of a Model field:

<header
	name="example" type="Model"
	model="com_example.Items"
	key_field="example_item_id"
	value_field="title"
	translate="false"
	apply_access="true"
	none="COM_FOOBAR_ITEMS_MSG_NO_EXAMPLE_ITEM_SELECTED"
>
	<state key="enabled">1</state>
	<state key="language"><![CDATA[en_GB, *]]></state>
</header>

Clone this wiki locally