Skip to content
Nicholas K. Dionysopoulos edited this page Mar 5, 2015 · 1 revision

CallBack field

This field type allows you to get the field's contents using a callback, i.e. calling a static method of a specific class. The callback's results will appear as the field's contents.

This is typically useful for the following use cases:

  • Rendering complex fields without creating a custom field class
  • Including an external view in your form. Remember that the callback can do HMVC to call a view from the same or a different FOF-powered component.
  • Adding non-static Javascript and CSS.
  • Render input elements that are not possible with the other field types

The following attributes are used to specify the callback.

source_file

(optional) The PHP file which provides the class and method. It is given in the pseudo-URL format e.g. admin://components/com_foobar/helpers/mydata.php or site://components/com_foobar/helpers/mydata.php for a file relative to the administrator or site root directory respectively. You do NOT need to use this attribute for auto-loaded classes, e.g. Helper classes of any FOF-powered component.

source_class

(required) The fully qualified name of the PHP class to use, e.g. \Acme\Example\Admin\Helper\Select

source_method

(required) The static method of the PHP class to use, e.g. selectFoobars.

FOF passes an indexed array of variables to the method. The array contains the following keys:

  • model (type FOF30\Model\DataModel) The model of the form being rendered
  • form (type FOF30\Form\Form) The form currently being rendered
  • formType (type string) The type of the form being rendered, e.g. "read" or "edit"
  • fieldValue (type mixed) The value of the form field, if you are using a name / name_from attribute that corresponds to an existing field in your Model
  • fieldElement (type SimpleXMLElement) The XML source of the field being rendered
Clone this wiki locally