You are here

public function FlexiformElementEntityProperty::form in Flexiform 7

Return the form element for this FlexiformElement.

Overrides FlexiformElement::form

1 call to FlexiformElementEntityProperty::form()
FlexiformElementEntityProperty_date::form in includes/element/property/date.property.element.inc
Return the form element for this FlexiformElement.
1 method overrides FlexiformElementEntityProperty::form()
FlexiformElementEntityProperty_date::form in includes/element/property/date.property.element.inc
Return the form element for this FlexiformElement.

File

includes/element/property.element.inc, line 68
Contains class for the entity property elements.

Class

FlexiformElementEntityProperty
Class to add an element for entity properties.

Code

public function form($form, &$form_state, $entity, $language = LANGUAGE_NONE) {
  $parents = $form['#parents'];
  $parents[] = $this->property;

  // Get the value.
  $value = $this
    ->wrapper($entity)
    ->get($this->property)
    ->value();

  // If there is no value work out the default.
  if (empty($value)) {
    $value = '';
    if (isset($this->settings['default_value']['default_value'])) {
      $value = $this->settings['default_value']['default_value'];
    }
    if (!empty($this->settings['default_value']['use_tokens'])) {
      $value = $this
        ->replaceCtoolsSubstitutions($value, $form['#flexiform_entities']);
    }
  }
  else {
    if (entity_get_info($this->dataType)) {
      $value = entity_id($this->dataType, $value);
    }
  }
  $form[$this->element_namespace] = array(
    '#type' => 'textfield',
    '#parents' => $parents,
    '#title' => $this
      ->label(),
    '#required' => !empty($this->settings['required']),
    '#default_value' => $value,
    '#maxlength' => 255,
  );

  // If the property specifies an options list then use it.
  if ($options = $this
    ->property($entity)
    ->optionsList()) {

    // Pick the list widget.
    $widget = 'select';
    if (!empty($this->settings['options']['widget'])) {
      $widget = $this->settings['options']['widget'];
    }
    $form[$this->element_namespace]['#type'] = $widget;
    if ($widget == 'select') {
      $form[$this->element_namespace]['#empty_option'] = t('- Select -');
    }
    $form[$this->element_namespace]['#options'] = $options;
    unset($form[$this->element_namespace]['#maxlength']);
    if ($this->isList) {
      $form[$this->element_namespace]['#multiple'] = TRUE;
      if ($widget == 'radios') {
        $form[$this->element_namespace]['#type'] = 'checkboxes';
      }
    }
  }
  $form = parent::form($form, $form_state, $entity);
  return $form;
}