You are here

function field_kaltura_widget in Kaltura 5

Same name and namespace in other branches
  1. 6.2 plugins/field_kaltura/field_kaltura.module \field_kaltura_widget()
  2. 6 plugins/field_kaltura/field_kaltura.module \field_kaltura_widget()

Implementation of hook_widget().

Attach a single form element to the form. It will be built out and validated in the callback(s) listed in hook_elements. We build it out in the callbacks rather than here in hook_widget so it can be plugged into any module that can provide it with valid $field information.

Content module will set the weight, field name and delta values for each form element. This is a change from earlier CCK versions where the widget managed its own multiple values.

If there are multiple values for this field, the content module will call this function as many times as needed.

Parameters

$form: the entire form array, $form['#node'] holds node information

$form_state: the form_state, $form_state['values'][$field['field_name']] holds the field's form values.

$field: the field array

$items: array of default values for this field

$delta: the order of this item in the array of subelements (0, 1, 2, etc)

Return value

the form item for a single element for this field

File

plugins/field_kaltura/field_kaltura.module, line 417
kaltura integration module - functions to provide kaltura as CCK field

Code

function field_kaltura_widget($op, &$node, $field, &$items) {
  switch ($op) {
    case 'form':
      $form = array();
      $form[$field['field_name']] = array(
        '#tree' => TRUE,
      );
      if ($field['multiple']) {
        $form[$field['field_name']]['#type'] = 'fieldset';
        $form[$field['field_name']]['#description'] = content_filter_xss(t($field['widget']['description']));
        $delta = 0;

        // real widgets
        foreach ($items as $data) {
          if ($data['value']) {
            field_kaltura_remix_textfield_process($field, $edit, $form_state, $form, $items, $delta);
            $delta++;
          }
        }

        // adding empty widgets
        foreach (range($delta, $delta + 2) as $delta) {
          field_kaltura_remix_textfield_process($field, $edit, $form_state, $form, $items, $delta, $no_content);
        }
      }
      else {
        if ($field['type'] == 'Kaltura_Media') {
          field_kaltura_textfield_process($field, $edit, $form_state, $form, $items);
        }
        if ($field['type'] == 'Kaltura_Media_Remix') {
          field_kaltura_remix_textfield_process($field, $edit, $form_state, $form, $items);
        }
      }
      return $form;
    case 'process form values':

      // Don't save empty fields except the first value
      foreach ($items as $delta => $item) {
        if ($item['value'] == '' && $delta > 0) {
          unset($items[$delta]);
        }
      }
      break;
  }
}