You are here

protected function SchemaFormBuilder::typeHandler in Migrate API 8

Same name and namespace in other branches
  1. 8.2 src/SchemaFormBuilder.php \Drupal\migrate_api\SchemaFormBuilder::typeHandler()

Handle building a form when something has a "type".

Parameters

array $schema: A schema plugin definition or subtree.

string $context: The key for the form subtree currently being built.

array $form: The form or form subtree to attach elements to.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the form the subtree is attached to, for AJAX reasons.

File

src/SchemaFormBuilder.php, line 123
Contains \Drupal\migrate_api\SchemaFormBuilder.

Class

SchemaFormBuilder
Builds forms from schema.

Namespace

Drupal\migrate_api

Code

protected function typeHandler($schema, $context, &$form, FormStateInterface $form_state) {
  if ($context === SchemaFormBuilderInterface::ROOT_CONTEXT_KEY) {
    return;
  }

  // If we don't have a way to handle a type, perhaps it can be resolved to
  // something more primative. @todo investigate moving resolving a type to
  // the most primatve types.
  if (empty($this->primativeTypeMap[$schema['type']]) && strpos($schema['type'], '%') === FALSE) {

    // @todo, find out why TypedConfigManager squashes ancesty information.
    $type_definition = $this->configManager
      ->getDefinitions()[$schema['type']];

    // Preserve labels when resolving parents.
    if (!isset($type_definition['label']) && isset($schema['label'])) {
      $type_definition['label'] = $schema['label'];
    }
    $this
      ->processSchema($type_definition, $context, $form, $form_state);
  }
  else {
    $form[$context] = [
      '#title' => isset($schema['label']) ? $schema['label'] : '',
      '#type' => !empty($this->primativeTypeMap[$schema['type']]) ? $this->primativeTypeMap[$schema['type']] : 'textfield',
    ];
  }
}