protected function SchemaFormBuilder::sequenceHandler in Migrate API 8
Same name and namespace in other branches
- 8.2 src/SchemaFormBuilder.php \Drupal\migrate_api\SchemaFormBuilder::sequenceHandler()
Handle building a form when a sequence is encountered.
Parameters
array $schema: A schema plugin definition or subtree.
string $context: 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 178 - Contains \Drupal\migrate_api\SchemaFormBuilder.
Class
- SchemaFormBuilder
- Builds forms from schema.
Namespace
Drupal\migrate_apiCode
protected function sequenceHandler($schema, $context, &$form, $form_state) {
$unique_ajax_key = $this
->uniqueAjaxId($schema, $context);
foreach (range(0, $form_state
->get([
'schema_form_deltas',
$unique_ajax_key,
]) ?: 0) as $delta) {
$this
->processSchema($schema['sequence'], $delta, $form[$context], $form_state);
}
$form[$context]['add'] = [
'#type' => 'submit',
'#value' => $this
->t('Add another'),
'#name' => $unique_ajax_key,
'#submit' => [
[
static::class,
'sequenceHandlerSubmit',
],
],
'#ajax' => [
'callback' => [
static::class,
'sequenceHandlerAjax',
],
'wrapper' => $unique_ajax_key,
],
];
$form[$context]['#prefix'] = "<div id=\"{$unique_ajax_key}\">";
$form[$context]['#suffix'] = '</div>';
return $form;
}