You are here

class Property in Form Builder 7.2

Same name in this branch
  1. 7.2 examples/src/Property.php \Drupal\form_builder_examples\Property
  2. 7.2 modules/webform/src/Property.php \Drupal\form_builder_webform\Property

Form builder property for the example form type.

Hierarchy

Expanded class hierarchy of Property

1 file declares its use of Property
form_builder_examples.module in examples/form_builder_examples.module
form_builder_examples.module Sample implementations of form_builder.

File

examples/src/Property.php, line 10

Namespace

Drupal\form_builder_examples
View source
class Property extends PropertyBase {
  protected $property;
  protected $params;
  protected $formTypeName;

  /**
   * Generate form-API elements for editing this property.
   *
   * @param array $form_state
   *   Form API form_state of the field configure form.
   * @param \Drupal\form_builder\ElementInterface $element
   *   The currently stored element. Use this to get the "current" values.
   *
   * @return array
   *   Form-API array that will be merged into the field configure form.
   */
  public function form(&$form_state, $element) {
    $e = $element
      ->render();
    if (isset($this->params['form']) && function_exists($this->params['form'])) {
      $function = $this->params['form'];
      $p = $this->property;

      // Set a default value on the property to avoid notices.
      $e['#' . $p] = isset($e['#' . $p]) ? $e['#' . $p] : NULL;
      return $function($form_state, $this->formTypeName, $e, $p);
    }
    return array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Property::$formTypeName protected property Overrides PropertyBase::$formTypeName
Property::$params protected property Overrides PropertyBase::$params
Property::$property protected property Overrides PropertyBase::$property
Property::form public function Generate form-API elements for editing this property.
PropertyBase::submit public function Submit handler for the editing form(). Overrides PropertyInterface::submit 1
PropertyBase::__construct public function Construct a new instance of this property class. Overrides PropertyInterface::__construct 1