You are here

protected function ModuleBuilderComponentFormBase::elementString in Module Builder 7.2

Set form element properties specific to array component properties.

Parameters

&$element: The form element for the component property.

FormStateInterface $form_state: The form state.

$property_info: The info array for the component property.

$form_default_value: The default value for the form element.

Return value

string The handling type to be applied to this element's value on submit.

File

includes/module_builder.form.inc, line 589

Class

ModuleBuilderComponentFormBase
Backport of ComponentFormBase from 8.x-3.x version.

Code

protected function elementString(&$element, FormStateInterface $form_state, $property_info, $form_default_value) {
  if (isset($property_info['options'])) {
    $element['#type'] = 'select';
    $options = [];
    $element['#options'] = $property_info['options'];
    $element['#empty_value'] = '';
    if (empty($form_default_value)) {
      $form_default_value = '';
    }
    $handling = 'select';
  }
  else {
    $element['#type'] = 'textfield';
    $handling = 'textfield';
  }
  $element['#default_value'] = $form_default_value;
  return $handling;
}