You are here

function quickedit_field_form_simplify in Quick Edit 7

Removes unneeded elements from the field from.

See also

Drupal 8's QuickEditFieldForm::simplify().

1 call to quickedit_field_form_simplify()
quickedit_field_form in includes/pages.inc
Form constructor; in-place editing form for a (single) Field API or "extra" field.

File

includes/pages.inc, line 436
AJAX endpoint to retrieve & save subforms for fields and re-render fields.

Code

function quickedit_field_form_simplify(&$form, &$form_state) {
  $field_name = $form_state['field_name'];
  $langcode = $form_state['langcode'];
  if (_quickedit_is_extra_field($form_state['entity_type'], $field_name)) {
    $key = quickedit_extra_field_info($form_state['entity_type'], $field_name, 'form simplification element key');
    $widget_element =& $form[$key];
  }
  else {
    $widget_element =& $form[$field_name][$langcode];
  }

  // Hide the field label from displaying within the form, because JavaScript
  // displays the equivalent label that was provided within an HTML data
  // attribute of the field's display element outside of the form. Do this for
  // widgets without child elements (like Option widgets) as well as for ones
  // with per-delta elements. Skip single checkboxes, because their title is
  // key to their UI. Also skip widgets with multiple subelements, because in
  // that case, per-element labeling is informative.
  $num_children = count(element_children($widget_element));
  if ($num_children == 0 && $widget_element['#type'] != 'checkbox') {
    $widget_element['#title_display'] = 'invisible';
  }
  if ($num_children == 1 && isset($widget_element[0]['value'])) {

    // @todo While most widgets name their primary element 'value', not all
    //   do, so generalize this.
    $widget_element[0]['value']['#title_display'] = 'invisible';
  }

  // Adjust textarea elements to fit their content.
  if (isset($widget_element[0]['value']['#type']) && $widget_element[0]['value']['#type'] == 'textarea') {
    $lines = count(explode("\n", $widget_element[0]['value']['#default_value']));
    $widget_element[0]['value']['#rows'] = $lines + 1;
  }
}