You are here

protected function PdbBlock::createElementsFromConfiguration in Decoupled Blocks 8

Create Form API elements from component configuration.

Parameters

array $configuration: The configuration array.

\Drupal\Core\Form\FormStateInterface $form_state: The form state array.

Return value

array Form elements.

1 call to PdbBlock::createElementsFromConfiguration()
PdbBlock::buildComponentSettingsForm in src/Plugin/Block/PdbBlock.php
Build settings component settings form.

File

src/Plugin/Block/PdbBlock.php, line 302

Class

PdbBlock
Class PdbBlock.

Namespace

Drupal\pdb\Plugin\Block

Code

protected function createElementsFromConfiguration($configuration, FormStateInterface $form_state) {
  $elements = [];
  $defaults = !empty($this->configuration['pdb_configuration']) ? $this->configuration['pdb_configuration'] : [];
  foreach ($configuration as $key => $setting) {
    $element = [];
    foreach ($setting as $property_key => $property) {

      // @todo Create whitelist or blacklist of form api properties
      $element["#{$property_key}"] = $property;
    }
    if (isset($defaults[$key])) {
      $element['#default_value'] = $this
        ->getElementDefaultValue($defaults[$key]);
    }
    $elements[$key] = $element;
  }
  return $elements;
}