You are here

function views_oai_pmh_plugin_row_misc::options_form in Views OAI-PMH 7.2

Same name and namespace in other branches
  1. 6.2 plugins/views_oai_pmh_plugin_row_misc.inc \views_oai_pmh_plugin_row_misc::options_form()

Build the Views options form.

Overrides views_plugin_row::options_form

File

plugins/views_oai_pmh_plugin_row_misc.inc, line 124
Definition of the views_oai_pmh_plugin_row_misc class.

Class

views_oai_pmh_plugin_row_misc
@file Definition of the views_oai_pmh_plugin_row_misc class.

Code

function options_form(&$form, &$form_state) {

  // Call the parent class' form builder function.
  parent::options_form($form, $form_state);
  $field_handlers = $this->display->handler
    ->get_handlers('field');
  foreach ($field_handlers as $id => $handler) {
    $ui_labels[$id] = $handler
      ->ui_name();
    if ($label_string = $handler
      ->label()) {

      // See if the label contains formatting HTML that we need to remove.
      if (strpos($label_string, '<span') !== FALSE) {

        // Grab the contents of the first 'span' tag in the label.
        $label_string = substr($label_string, 0, strpos($label_string, '<span>', 1));

        // Strip the span tag, leaving us with just the labels.
        $label_string = strip_tags($label_string);
      }

      // Break the label string into its component labels, which are separated by commas.
      $labels[$id] = explode(', ', $label_string);
    }
  }

  // Copy the name of the form field into a local variable for easy reference.
  $form_group_name = $GLOBALS['views_oai_pmh'][$this->_metadata_format]->form_group_name;
  $form[$form_group_name] = array(
    '#type' => 'fieldset',
    '#title' => t('Drupal field to @name mapping', array(
      '@name' => $GLOBALS['views_oai_pmh'][$this->_metadata_format]->name,
    )),
    '#theme' => 'oai_field_mapper_form',
  );
  foreach ($ui_labels as $id => $label) {

    // Determine the default value for this element name.
    $default_value = 'none';
    if (isset($labels[$id]) && is_array($labels[$id])) {
      foreach ($labels[$id] as $label) {

        // Does this label exist in our elements names array above?
        if (array_key_exists($label, $GLOBALS['views_oai_pmh'][$this->_metadata_format]->elements)) {
          $default_value = $label;
        }
      }
    }
    $form[$form_group_name][$id] = array(
      '#type' => 'select',
      '#options' => $GLOBALS['views_oai_pmh'][$this->_metadata_format]->elements,
      '#default_value' => $default_value,
    );
    $form[$form_group_name][$id]['drupal_label'] = array(
      '#markup' => $ui_labels[$id],
    );
  }
}