You are here

function editablefields_views_form in Editable Fields 7

Form builder callback for Views-embedded forms.

1 string reference to 'editablefields_views_form'
editablefields_field_formatter_view in ./editablefields.module
Implements hook_field_formatter_view().

File

./editablefields.module, line 446
Editable fields module.

Code

function editablefields_views_form($view, $views_field, &$form, &$form_state) {

  // Search for the field object in the $view->field array, so as to extract
  // its actual ID. Views doesn't provide any reliable way to do that otherwise.
  $field_id = array_search($views_field, $view->field, TRUE);
  if (!isset($form_state['editablefields'][$field_id])) {
    $form_state['editablefields'][$field_id] = array(
      'rows' => $views_field->editablefield_data,
      'field' => $views_field->editablefield_field,
      'instance' => $views_field->editablefield_instance,
    );
  }
  $field = $form_state['editablefields'][$field_id]['field'];
  $instance = $form_state['editablefields'][$field_id]['instance'];
  foreach ($form_state['editablefields'][$field_id]['rows'] as $row_id => $row) {

    // $entity_type, $entity, $langcode, $display
    extract($row);
    if (isset($row['entity'])) {
      list($entity_id, ) = entity_extract_ids($entity_type, $row['entity']);
      if (!isset($form_state['editablefields_entities'][$entity_type][$entity_id])) {
        $form_state['editablefields_entities'][$entity_type][$entity_id] = $entity;
      }
      else {
        $entity = $form_state['editablefields_entities'][$entity_type][$entity_id];
      }
      $form_state['editablefields'][$field_id][$row_id]['entity_id'] = $entity_id;
      unset($form_state['editablefields'][$field_id][$row_id]['entity']);
    }
    else {
      $entity = $form_state['editablefields_entities'][$entity_type][$row['entity_id']];
    }
    $temp_form = array(
      '#parents' => array(
        $field_id,
        $row_id,
      ),
      '#tree' => TRUE,
    );
    $form[$field_id][$row_id] = editablefields_form($temp_form, $form_state, $entity_type, $entity, $field, $instance, $langcode, $display);
  }

  // Remove our temporary data to make the views object smaller.
  // It's particularly important because some modules (e.g. Devel), try to
  // serialize it unconsiderably.
  unset($views_field->editablefield_data);

  // $form_state['build_info']['args'] = array();
}