class data__sequence_widget

Hierarchy

Expanded class hierarchy of data__sequence_widget

2 string references to 'data__sequence_widget'
data__sequence.inc in tripal_chado/includes/TripalFields/data__sequence/data__sequence.inc
tripal_chado_bundle_instances_info_custom in tripal_chado/includes/tripal_chado.fields.inc
Helper function for the hook_create_tripalfield_instance().

File

tripal_chado/includes/TripalFields/data__sequence/data__sequence_widget.inc, line 3

View source
class data__sequence_widget extends ChadoFieldWidget {
  // The default lable for this field.
  public static $default_label = 'Sequence';

  // The list of field types for which this formatter is appropriate.
  public static $field_types = array('data__sequence');

  /**
   *
   * @see TripalFieldWidget::form()
   */
  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
    parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);

    $settings = $this->field['settings'];
    $field_name = $this->field['field_name'];
    $field_type = $this->field['type'];
    $field_table = $this->instance['settings']['chado_table'];
    $field_column = $this->instance['settings']['chado_column'];

    // Get the field defaults.
    $residues = '';
    if (count($items) > 0 and array_key_exists('value', $items[0])) {
      $residues = $items[0]['value'];
    }
    if (array_key_exists('values', $form_state) and 
      array_key_exists($field_name, $form_state['values'])) {
      $residues = $form_state['values'][$field_name][$langcode][$delta]['value'];
    }

    $widget['value'] = array(
      '#type' => 'value',
      '#value' => $residues,
    );

    $widget['chado-' . $field_table . '__' . $field_column] = array(
      '#type' => 'textarea',
      '#title' => $element['#title'],
      '#description' => $element['#description'],
      '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
      '#default_value' => $residues,
      '#delta' => $delta,
      '#cols' => 30,
    );
  }


  /**
   *
   * @see TripalFieldWidget::submit()
   */
  public function validate($element, $form, &$form_state, $langcode, $delta) {
    $field_name = $this->field['field_name'];
    $field_table = $this->instance['settings']['chado_table'];
    $field_column = $this->instance['settings']['chado_column'];

    // Remove any white spaces.
    $residues = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column];
    if ($residues) {
      $residues = preg_replace('/\s/', '', $residues);
      $form_state['values'][$field_name]['und'][$delta]['value'] = $residues;
      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column] = $residues;
    }
    // If the residue information has been removed then we want to signal such.
    // When it's removed the value != residues but if it was never set then they're both empty.
    elseif (!empty($form_state['values'][$field_name]['und'][$delta]['value'])) {
      $form_state['values'][$field_name]['und'][$delta]['value'] = 'delete_me';
      $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__' . $field_column] = '';
    }
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
data__sequence_widget::$default_label public static property Overrides TripalFieldWidget::$default_label
data__sequence_widget::$field_types public static property Overrides TripalFieldWidget::$field_types
data__sequence_widget::form public function Overrides TripalFieldWidget::form
data__sequence_widget::validate public function Overrides TripalFieldWidget::validate
TripalFieldWidget::info public static function Provides information about the widgets provided by this field.
TripalFieldWidget::submit public function Performs extra commands when the entity form is submitted.
TripalFieldWidget::theme public function The theme function for the widget.
TripalFieldWidget::__construct public function Instantiates a new TripalFieldWidget object.