1 field_permission_example.module field_permission_example_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element)

Implements hook_field_widget_form().

Backdrop wants us to create a form for our field. We'll use something very basic like a default textarea.

See also

field_permission_example_field_widget_info()

Related topics

File

modules/examples/field_permission_example/field_permission_example.module, line 279
An example field using the Field Types API.

Code

function field_permission_example_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  // Grab the existing value for the field.
  $value = isset($items[$delta]['notes']) ? $items[$delta]['notes'] : '';
  // Grab a reference to the form element.
  $widget = $element;
  // Set up the delta for our return element.
  $widget['#delta'] = $delta;

  // Figure out which widget we need to generate.
  // In our case, there's only one type.
  switch ($instance['widget']['type']) {
    case 'field_permission_example_widget':
      $widget += array(
        '#type' => 'textarea',
        '#default_value' => $value,
      );
      break;
  }

  $element['notes'] = $widget;
  return $element;
}