You are here

function kaltura_manage_fields_mapping in Kaltura 7.3

Page callback: Constructs a form for the mapping of remote to local fields.

See also

kaltura_manage_fields_mapping_submit()

kaltura_menu()

1 string reference to 'kaltura_manage_fields_mapping'
kaltura_menu in ./kaltura.module
Implements hook_menu().

File

includes/kaltura.admin.inc, line 1015
Contains functions for administration use of the kaltura core module.

Code

function kaltura_manage_fields_mapping($form, &$form_state) {
  $form['kaltura_fields_map'] = array(
    '#type' => 'container',
    '#tree' => TRUE,
  );
  $map = variable_get('kaltura_fields_map', array());

  // Prepare the options array. It is the list of remote fields.
  // @todo Different options for different field types and cardinality.
  $options = array();
  $helpers = new KalturaHelpers();
  foreach ($helpers
    ->getMetadataFieldList() as $profile_id => $data) {
    $profile_name = $data['metadata_profile']->name;
    foreach ($data['field_info'] as $field_name => $instance) {

      // Get the field type.
      $type = (string) $instance
        ->attributes()->type;
      if (!$type && !empty($instance->simpleType)) {
        $type = (string) $instance->simpleType->restriction
          ->attributes()->base;
      }
      if (!$type) {

        // This is some complex type of the field.
        continue;
      }
      if (substr($type, -4) == 'Type') {
        $type = substr($type, 0, -4);
      }
      $label = (string) $instance->annotation->appinfo
        ->children()->label;
      $cardinality = (string) $instance
        ->attributes()->maxOccurs;
      $value = $profile_id . '/' . $field_name;

      // Each option group corresponds to one profile. Options will be escaped
      // by form_select_options() so do not escape them here.
      $options[$profile_name][$value] = t('!label (type: !type; max num of values: !cardinality)', array(
        '!label' => $label,
        '!type' => $type,
        '!cardinality' => $cardinality,
      ));
    }
  }

  // Create a select element for each of Kaltura Media Entry fields.
  $field_instances = field_info_instances('kaltura_entry', 'kaltura_entry');
  foreach ($field_instances as $field_name => $instance) {
    $field = field_info_field($field_name);
    $field_type = field_info_field_types($field['type']);
    if (!isset($field['columns']['value'])) {

      // Field types without 'value' column are not supported currently.
      continue;
    }
    $hints = array();
    $hints[] = t('The type of this field is <strong>@type</strong>.', array(
      '@type' => $field_type['label'],
    ));
    if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
      $hints[] = t('This field can contain maximum of <strong>@cardinality</strong> value(s).', array(
        '@cardinality' => $field['cardinality'],
      ));
    }
    $form['kaltura_fields_map'][$field_name] = array(
      '#type' => 'select',
      '#title' => $instance['label'] . ' <em>(' . $field_name . ')</em>',
      '#description' => implode("<br/>", $hints),
      '#options' => $options,
      '#empty_value' => '',
      '#default_value' => isset($map[$field_name]) ? $map[$field_name] : '',
      '#weight' => $instance['widget']['weight'],
    );
  }
  $form = system_settings_form($form);
  $form['#submit'][] = 'kaltura_manage_fields_mapping_submit';
  return $form;
}