You are here

public function FlexiformElementField::form in Flexiform 7

Return the form element for this FlexiformElement.

Overrides FlexiformElement::form

2 calls to FlexiformElementField::form()
FlexiformElementField_entityreference::form in includes/element/fields/entityreference.inc
Return the form element for this FlexiformElement.
FlexiformElementField_field_collection::form in includes/element/fields/field_collection.inc
Return the form element for this FlexiformElement.
2 methods override FlexiformElementField::form()
FlexiformElementField_entityreference::form in includes/element/fields/entityreference.inc
Return the form element for this FlexiformElement.
FlexiformElementField_field_collection::form in includes/element/fields/field_collection.inc
Return the form element for this FlexiformElement.

File

includes/element/field.element.inc, line 383
Contains FlexiformElementField class.

Class

FlexiformElementField
Class for Field API elements.

Code

public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
  $items = field_get_items($this->entity_type, $entity, $this->field_name, $language);

  // field_default_form expects $items to be an array or NULL but
  // field_get_items returns FALSE when there are none. If $items is FALSE
  // turn it into an empty array to prevent errors later on.
  if (!$items) {
    $items = array();
  }
  if (!field_info_field($this->field_name) || !field_info_instance($this->entity_type, $this->field_name, $this->bundle)) {
    debug("Error in " . __CLASS__ . "::" . __METHOD__ . ": Field <em>{$this->field_name}</em> does not exist or does not have an instance on {$this->entity_type}:{$this->bundle}.", "error");
    return $form;
  }
  $instance = $this
    ->getInstance();

  // Deal with default value tokens.
  if ($this
    ->checkWidgetBehavior() && !empty($instance['use_default_value_tokens'])) {
    $defaults =& $instance['default_value'];
    foreach ($defaults as $delta => &$item) {
      foreach ($item as &$value) {
        if (is_string($value)) {
          $value = $this
            ->replaceCtoolsSubstitutions($value, $form['#flexiform_entities']);
        }
      }
    }
  }
  $form_fields = field_default_form($this->entity_type, $entity, $this
    ->getField(), $instance, $language, $items, $form, $form_state);
  foreach ($form_fields as $form_key => $form_field) {

    // Make sure the parents stuff is always correct.
    $form_field['#parents'] = $form['#parents'];
    array_push($form_field['#parents'], $this->field_name);
    if (!empty($instance['remove_none'])) {
      unset($form_field[$language]['#options']['']);
      unset($form_field[$language]['#options']['_none']);
    }
    if (isset($instance['attributes']) && is_array($instance['attributes'])) {
      if (isset($form_field['#attributes'])) {
        $form_field['#attributes'] = array_replace_recursive($form_field['#attributes'], $instance['attributes']);
      }
      else {
        $form_field['#attributes'] = $instance['attributes'];
      }
    }

    // Honour the hide title settings.
    if (!empty($this->settings['display_options']['hide_label'])) {
      $form_field[LANGUAGE_NONE]['#title_display'] = 'invisible';
    }
    $form[$this->element_namespace] = $form_field;
  }
  $form = parent::form($form, $form_state, $entity);
  return $form;
}