You are here

class Element in Form Builder 7.2

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

Hierarchy

Expanded class hierarchy of Element

1 file declares its use of Element
form_builder_webform.module in modules/webform/form_builder_webform.module
Form Builder integration for the Webform module.

File

modules/webform/src/Element.php, line 7

Namespace

Drupal\form_builder_webform
View source
class Element extends ElementBase {

  /**
   * {@inheritdoc}
   */
  protected function setProperty($property, $value) {
    $component =& $this->element['#webform_component'];
    $properties = $this
      ->getProperties();
    $properties[$property]
      ->setValue($component, $value);
  }

  /**
   * {@inheritdoc}
   */
  public function render() {
    $element = $this->element;
    if (isset($element['#webform_component'])) {
      $component = $element['#webform_component'];
      $new_element = webform_component_invoke($component['type'], 'render', $component, NULL, FALSE);

      // Preserve the #weight. It may have been changed by the positions form.
      $new_element['#weight'] = $element['#weight'];
      $new_element['#key'] = $component['form_key'];
      $new_element['#webform_component'] = $component;
      $new_element['#form_builder'] = $element['#form_builder'];
      return $this
        ->addPreRender($new_element);
    }
    return $this
      ->addPreRender($element);
  }
  public function title() {
    return $this->element['#webform_component']['name'];
  }

  /**
   * Get the element’s form key.
   *
   * @return string
   *   The element’s form key.
   */
  public function key() {
    return $this->element['#webform_component']['form_key'];
  }

  /**
   * Generate the component edit form for this component.
   *
   * @return array
   *   Form-API array of the component edit form.
   */
  protected function componentEditForm($component) {
    $component = $this->element['#webform_component'];
    $form_id = 'webform_component_edit_form';
    $form_state = form_state_defaults();
    $nid = isset($component['nid']) ? $component['nid'] : NULL;
    $node = !isset($nid) ? (object) array(
      'nid' => NULL,
      'webform' => webform_node_defaults(),
    ) : node_load($nid);

    // The full node is needed here so that the "private" option can be access
    // checked.
    $form = $form_id([], $form_state, $node, $component);

    // We want to avoid a full drupal_get_form() for now but some alter hooks
    // need defaults normally set in drupal_prepare_form().
    $form += [
      '#submit' => [],
    ];
    $form_state['build_info']['args'][1] = $component;
    drupal_alter([
      'form',
      'form_webform_component_edit_form',
    ], $form, $form_state, $form_id);
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function configurationForm($form, &$form_state) {
    form_load_include($form_state, 'properties.inc', 'form_builder_webform');
    $component = $this->element['#webform_component'];
    $edit = $this
      ->componentEditForm($component);
    foreach ($this
      ->getProperties() as $property) {
      $form = array_merge($form, $property
        ->form($component, $edit, $form_state));
    }
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Element::componentEditForm protected function Generate the component edit form for this component.
Element::configurationForm public function Get the configuration form for this element. Overrides ElementInterface::configurationForm 1
Element::key public function Get the element’s form key. Overrides ElementBase::key
Element::render public function (Re-)Render an element. Overrides ElementBase::render
Element::setProperty protected function Set the value of a property. Overrides ElementBase::setProperty
Element::title public function Get a human-readable title for this form element. Overrides ElementBase::title
ElementBase::$element protected property
ElementBase::$form protected property
ElementBase::$loader protected property
ElementBase::$params protected property
ElementBase::addPreRender protected function Add our pre-render function to the element-array.
ElementBase::configurationSubmit public function Submit handler for the configuration form. Overrides ElementInterface::configurationSubmit 1
ElementBase::getProperties public function Get a list of properties available for this element. Overrides ElementInterface::getProperties
ElementBase::getSaveableProperties public function Get a list of properties that are supported in any way by this element. Overrides ElementInterface::getSaveableProperties
ElementBase::parentId public function
ElementBase::__construct public function Overrides ElementInterface::__construct