public function TripalFieldWidget::form

3.x TripalFieldWidget.inc public TripalFieldWidget::form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element)

Provides the form for editing of this field.

This function corresponds to the hook_field_widget_form() function of the Drupal Field API.

This form is diplayed when the user creates a new entity or edits an existing entity. If the field is attached to the entity then the form provided by this function will be displayed.

At a minimum, the form must have a 'value' element. For Tripal, the 'value' element of a field always corresponds to the value that is presented to the end-user either directly on the page (with formatting) or via web services, or some other mechanism. However, the 'value' is sometimes not enough for a field. For example, the Tripal Chado module maps fields to table columns and sometimes those columns are foreign keys therefore, the Tripal Chado modules does not just use the 'value' but adds additional elements to help link records via FKs. But even in this case the 'value' element must always be present in the return form and in such cases it's value should be set equal to that added in the 'load' function.

Parameters

$widget:

$form: The form structure where widgets are being attached to. This might be a full form structure, or a sub-element of a larger form.

$form_state: An associative array containing the current state of the form.

$langcode: The language associated with $items.

$items: Array of default values for this field.

$delta: The order of this item in the array of subelements (0, 1, 2, etc).

$element: A form element array containing basic properties for the widget:

  • #entity_type: The name of the entity the field is attached to.
  • #bundle: The name of the field bundle the field is contained in.
  • #field_name: The name of the field.
  • #language: The language the field is being edited in.
  • #field_parents: The 'parents' space for the field in the form. Most widgets can simply overlook this property. This identifies the location where the field values are placed within $form_state['values'], and is used to access processing information for the field through the field_form_get_state() and field_form_set_state() functions.
  • #columns: A list of field storage columns of the field.
  • #title: The sanitized element label for the field instance, ready for output.
  • #description: The sanitized element description for the field instance, ready for output.
  • #required: A Boolean indicating whether the element value is required; for required multiple value fields, only the first widget's values are required.
  • #delta: The order of this item in the array of subelements; see $delta above
30 calls to TripalFieldWidget::form()
chado_linker__contact_widget::form in tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc
chado_linker__prop_widget::form in tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
data__accession_widget::form in tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc
data__protein_sequence_widget::form in tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence_widget.inc
data__sequence_checksum_widget::form in tripal_chado/includes/TripalFields/data__sequence_checksum/data__sequence_checksum_widget.inc

... See full list

30 methods override TripalFieldWidget::form()
chado_linker__contact_widget::form in tripal_chado/includes/TripalFields/chado_linker__contact/chado_linker__contact_widget.inc
chado_linker__prop_widget::form in tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
data__accession_widget::form in tripal_chado/includes/TripalFields/data__accession/data__accession_widget.inc
data__protein_sequence_widget::form in tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence_widget.inc
data__sequence_checksum_widget::form in tripal_chado/includes/TripalFields/data__sequence_checksum/data__sequence_checksum_widget.inc

... See full list

File

tripal/includes/TripalFields/TripalFieldWidget.inc, line 103

Class

TripalFieldWidget

Code

public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {

  $widget['value'] = array(
    '#type' => 'value',
    '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
  );
  $widget['#field'] = $this->field;
  $widget['#instance'] = $this->instance;
  $widget['#element_validate'] = array('tripal_field_widget_form_validate');
  $widget['#theme'] = 'tripal_field_default';
}