public function remote__data::instanceSettingsForm

3.x remote__data.inc public remote__data::instanceSettingsForm()

Overrides TripalField::instanceSettingsForm

See also

TripalField::settingsForm()

File

tripal_ws/includes/TripalFields/remote__data/remote__data.inc, line 216

Class

remote__data
@class Purpose:

Code

public function instanceSettingsForm() {
  $element = parent::instanceSettingsForm();

  // Get the setting for the option for how this widget.
  $instance = $this->instance;
  $settings = '';
  $site_list = '';

  $tokens = array();
  // Get the form info from the bundle about to be saved.
  $bundle = tripal_load_bundle_entity(array('name' => $instance['bundle']));
  // Retrieve all available tokens.
  $tokens = tripal_get_entity_tokens($bundle);

  $element['data_info'] = array(
    '#type' => 'fieldset',
    '#title' => 'Remote Data Settings',
    '#description' => 'These settings allow you to provide a Tripal web
        services query to identify content on another Tripal site and display
        that here within this field.  You must specify the query to execute and
        the field to display.',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#prefix' => "<div id='set_titles-fieldset'>",
    '#suffix' => '</div>',
  );

  // Get the site info from the tripal_sites table.
  $sites = db_select('tripal_sites', 's')
    ->fields('s')
    ->execute()->fetchAll();

  foreach ($sites as $site) {
    $rows[$site->id] = $site->name;
  }

  $element['data_info']['remote_site'] = array(
    '#type' => 'select',
    '#title' => t('Remote Tripal Site'),
    '#options' => $rows,
    '#default_value' => $this->instance['settings']['data_info']['remote_site'],
  );

  $element['data_info']['query'] = array(
    '#type' => 'textarea',
    '#title' => 'Query to Execute',
    '#description' => 'Build the query string that should be appended after the url. The tokens
      listed below may be used in your query build.',
    '#default_value' => $this->instance['settings']['data_info']['query'],
    '#rows' => 5,
    '#required' => TRUE
  );
  $element['data_info']['rd_field_name'] = array(
    '#type' => 'textfield',
    '#title' => 'Field to Display',
    '#description' => 'The results returned by the query should match
        entities (or records) from the selected remote site.  That entity
        will have multiple fields. Only one remote field can be shown by
        this field. Please enter the name of the field you would like
        to display.  Some fields have "subfields".  You can display a subfield
        rather than the entire field by entering a comma-separated sequence
        of subfields.  For example, for relationships, you may only want to
        show the "clause", therefore, the entry here would be: realtionship,clause.',
    '#default_value' => $this->instance['settings']['data_info']['rd_field_name'],
    '#required' => TRUE
  );
  $element['data_info']['token_display']['tokens'] = array(
    '#type' => 'hidden',
    '#value' => serialize($tokens)
  );

  $element['data_info']['token_display'] = array(
    '#type' => 'fieldset',
    '#title' => 'Available Tokens',
    '#description' => 'Copy the token and paste it into the "Query" text field above.',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE
  );

  $element['data_info']['token_display']['content'] = array(
    '#type' => 'item',
    '#markup' => theme_token_list($tokens),
  );

  $element['data_info']['description'] = array(
    '#type' => 'textarea',
    '#title' => 'Description',
    '#description' => 'Describe the data being pulled in.',
    '#default_value' => $this->instance['settings']['data_info']['description'],
    '#rows' => 1
  );

  $fid = $this->instance['settings']['data_info']['site_logo'] ? $this->instance['settings']['data_info']['site_logo'] : NULL;
  $file = NULL;
  if ($fid) {
    $file = file_load($fid);
  }
  $element['data_info']['site_logo'] = array(
    '#title' => 'Remote Site Logo',
    '#description' => t('When data is taken from a remote site and shown to the user,
         the site from which the data was retrieved is indicated.  If you would like to
         include the logo for the remote site, please upload an image here.'),
    '#type' => 'managed_file',
    '#default_value' => $file ? $file->fid : NULL,
    '#theme' => 'image_widget',
    '#attached' => array(
      'css' => array(
        'image-preview' => drupal_get_path('module', 'image') . '/image.css',
      ),
    ),
    'preview' => array(
      '#markup' => theme('image_style', array('style_name' => 'thumbnail', 'path' => $file ? $file->uri : '')),
    ),
  );

  return $element;
}