Date: Thu, 28 Mar 2024 18:42:14 -0400 (EDT) Message-ID: <1259049861.4961.1711665734890@docs.blesta.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4960_357827427.1711665734889" ------=_Part_4960_357827427.1711665734889 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
The InputFields class is automatically made available to an= y messenger. To begin using it simply initialize the object within your mes= senger method.
The following messenger methods must return an InputFields obj= ect:
Creating fields using the InputFields class allows you to define a set o= f input fields that may be displayed in a variety of contexts, without worr= ying about how those fields are contained. There are three aspects of creat= ing a field, described below, that include: creating the field label, creat= ing the field, and attaching the field to the label.
Creating a label will return a InputFields object.
<?php=20 class MyMessenger extends Messenger {=20 =20 ...=20 public function getConfigurationFields(&$vars =3D []) =09{ // Create the label $fields =3D new InputFields(); $my_label =3D $fields->label('My Field Label', 'my_field_label_i= d'); $fields->setField($my_label); return $fields; } } ?>
As with creating a label, creating a field will return a InputField obje= ct. The example below uses the InputFields::fieldText() me= thod, but others exist for creating radio buttons, textarea fields, and eve= rything else you'll need.
<?php=20 class MyMessenger extends Messenger {=20 ... public function getConfigurationFields(&$vars =3D []) =09{ // Create the label $fields =3D new InputFields(); $my_label =3D $fields->label('My Field Label', 'my_field_id'); =20 // Create the field $my_field =3D $fields->fieldText('my_field_name', 'default value= ', ['id' =3D> "my_field_id"]); =20 $fields->setField($my_label); return $fields; } } ?>
A field may be attached to a label using the InputField::attach(= ) method, or, instead, attach a label to a field using Inp= utField::setLabel().
<?php=20 class MyMessenger extends Messenger {=20 ... public function getConfigurationFields(&$vars =3D []) =09{ // Create the label $fields =3D new InputFields(); $my_label =3D $fields->label('My Field Label', 'my_field_id'); =20 // Create the field $my_field =3D $fields->fieldText('my_field_name', 'default value= ', ['id' =3D> "my_field_id"]); // Attach the field to the label $my_label->attach($my_field); =20 // OR, attach the label to the field, instead // $my_field->setLabel($my_label); $fields->setField($my_label); return $fields; } } ?>
Tooltips can be created using the InputFields::tooltip() method, then attached using InputField::attach(). In the= example below we've eliminated unnecessary variable declarations to give a= more concise example.
<?php=20 class MyMessenger extends Messenger {=20 ... public function getConfigurationFields(&$vars =3D []) =09{ // Create the label $fields =3D new InputFields(); $my_label =3D $fields->label('My Field Label', 'my_field_id'); // Create and attach the field to the label $my_label->attach($fields->fieldText('my_field_name', 'defaul= t value', ['id' =3D> "my_field_id"])); // Attach a tooltip to the label $my_label->attach($fields->tooltip('This is my tooltip')); $fields->setField($my_label); return $fields; } } ?>
Tooltips may only be set on top level = labels
A tooltip may not be attached to a label that is, itself, attached to a = field.
Multiple tooltips may be created per l= abel
... but that would be silly.
Blesta supports InputFields up to two levels deep. This allows you to ea= sily create a set of checkboxes or radio buttons associated with a single f= ield.
<?php=20 class MyMessenger extends Messenger {=20 ... public function getConfigurationFields(&$vars =3D []) =09{ // Create the label $fields =3D new InputFields(); $my_label =3D $fields->label('My Field Label', 'my_field_id'); =09=09// Create a field label displayed next to the checkbox =09=09$field_label =3D $fields->label('My Value', 'my_field_my_value_id'= ); // Create and attach the field to the label, set as checked (3rd pa= ram) if necessary $my_label->attach( =09=09=09$fields->fieldCheckbox( =09=09=09=09'my_field_name', =09=09=09=09'my_value', =09=09=09=09(isset($vars['my_field_name']) && $vars['my_field_name'= ] =3D=3D 'my_value'), =09=09=09=09['id' =3D> 'my_field_my_value_id'], =09=09=09=09$field_label =09=09=09) =09=09); // Attach a tooltip to the label $my_label->attach($fields->tooltip('This is my tooltip')); $fields->setField($my_label); return $fields; } } ?>
The InputFields class supports HTML content as well. You may choose to s= et nothing but HTML content, but the best practice is to set fields using t= he method mentioned in the section above and only set javascript and that s= ort of thing as HTML content.
To set HTML content use the InputFields::setHtml() method.
<?php class MyMessenger extends Messenger { ... public function getConfigurationFields(&$vars =3D []) =09{ $fields =3D new InputFields(); $fields->setHtml(' <script type=3D"text/javascript">alert(\'ok!\');</scri= pt> '); } } ?>