class local__contact_widget

Hierarchy

Expanded class hierarchy of local__contact_widget

3 string references to 'local__contact_widget'
local__contact.inc in tripal_chado/includes/TripalFields/local__contact/local__contact.inc
tripal_chado_bundle_instances_info_custom in tripal_chado/includes/tripal_chado.fields.inc
Helper function for the hook_create_tripalfield_instance().
tripal_chado_bundle_instances_info_linker in tripal_chado/includes/tripal_chado.fields.inc

File

tripal_chado/includes/TripalFields/local__contact/local__contact_widget.inc, line 3

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

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

  /**
   *
   * @see TripalFieldWidget::form()
   */
  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
    parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
    $field_name = $this->field['field_name'];
    $field_type = $this->field['type'];
    $base_table = $this->instance['settings']['base_table'];
    $field_table = $this->instance['settings']['chado_table'];
    $chado_column = $this->instance['settings']['chado_column'];
    $instance = $this->instance;

    $schema = chado_get_schema($field_table);
    $pkey = $schema['primary key'][0];

    // Get the field defaults.
    $record_id = '';
    $contact_id = '';
    $name = '';
    $value = '';

    $name_term = chado_get_semweb_term('contact', 'name');

    // Set the linker field appropriately.
    if ($field_table == 'biomaterial') {
      $linker_field = 'chado-biomaterial__biosourceprovider_id';
    }
    else {
      $linker_field = 'chado-' . $field_table . '__contact_id';
    }

    // If the field already has a value then it will come through the $items
    // array.  This happens when editing an existing record.
    if (count($items) > 0 and array_key_exists($delta, $items)) {
      $name = array_key_exists($name_term, $items[$delta]['value']) ? $items[$delta]['value'][$name_term] : $name;
      $record_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $field_table . '__' . $pkey, $record_id);
      if ($field_table == 'biomaterial') {
        $contact_id = tripal_get_field_item_keyval($items, $delta, $linker_field, $contact_id);
      }
    }

    // Check $form_state['values'] to see if an AJAX call set the values.
    if (array_key_exists('values', $form_state) and 
      array_key_exists($field_name, $form_state['values'])) {
      $name = $form_state['values'][$field_name]['und'][$delta]['name'];
    }

    $schema = chado_get_schema('contact');

    $widget['value'] = array(
      '#type' => 'value',
      '#value' => array_key_exists($delta, $items) ? $items[$delta]['value'] : '',
    );

    $widget['chado-' . $field_table . '__' . $pkey] = array(
      '#type' => 'value',
      '#default_value' => $record_id,
    );
    $widget[$linker_field] = array(
      '#type' => 'value',
      '#default_value' => $contact_id,
    );

    $widget['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Contact'),
      '#default_value' => $name,
      '#autocomplete_path' => 'admin/tripal/storage/chado/auto_name/contact',
      '#maxlength' => 100000,
    );

  }


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

    // Get information about this contact linke rtable.
    $schema = chado_get_schema($field_table);
    $pkey = $schema['primary key'][0];

    // Get the name from the form state.
    $name = $form_state['values'][$field_name]['und'][$delta]['name'];

    // Set the linker field appropriately.
    if ($field_table == 'biomaterial') {
      $linker_field = 'chado-biomaterial__biosourceprovider_id';
    }
    else {
      $linker_field = 'chado-' . $field_table . '__contact_id';
    }

    // If the user provided a name then we want to set the foreign key
    // value to be the chado_record_id
    if ($name) {
      $contact = chado_generate_var('contact', array('name' => $name));
      if ($contact) {
        $form_state['values'][$field_name]['und'][$delta][$linker_field] = $contact->contact_id;
        $form_state['values'][$field_name]['und'][$delta]['value'] = $name;
      }
    }
    // If no name is provided then we want to set the field for deletion.
    else {
      $form_state['values'][$field_name]['und'][$delta][$linker_field] = '';
    }
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
local__contact_widget::$default_label public static property Overrides TripalFieldWidget::$default_label
local__contact_widget::$field_types public static property Overrides TripalFieldWidget::$field_types
local__contact_widget::form public function Overrides TripalFieldWidget::form
local__contact_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.