diff -u b/src/Form/FillPdfFormForm.php b/src/Form/FillPdfFormForm.php --- b/src/Form/FillPdfFormForm.php +++ b/src/Form/FillPdfFormForm.php @@ -168,6 +168,20 @@ $default_entity_id = count($stored_default_entity_id) ? $stored_default_entity_id->first()->value : NULL; } + $form['default_entity_id'] = [ + '#title' => $this->t('Default entity'), + '#target_type' => $default_entity_type, + '#weight' => 13, + '#prefix' => '
', + '#suffix' => '
', + '#ajax' => [ + 'callback' => '::ajaxUpdateEntityId', + 'event' => 'autocompleteclose autocompletechange', + 'wrapper' => 'test-entity-wrapper', + 'progress' => ['type' => 'none'], + ], + ]; + // If a default entity type is set, allow selecting a default entity, too. if ($default_entity_type) { $storage = $this->entityTypeManager->getStorage($default_entity_type); @@ -194,21 +208,10 @@ '%type' => $default_entity_type, ]); } - $form['default_entity_id'] = [ + $form['default_entity_id'] += [ '#type' => 'entity_autocomplete', - '#title' => $this->t('Default entity'), - '#target_type' => $default_entity_type, - '#description' => $description, - '#weight' => 13, '#default_value' => $default_entity, - '#prefix' => '
', - '#suffix' => '
', - '#ajax' => [ - 'callback' => '::ajaxUpdateEntityId', - 'event' => 'autocompleteclose autocompletechange', - 'wrapper' => 'test-entity-wrapper', - 'progress' => ['type' => 'none'], - ], + '#description' => $description, ]; } else { @@ -221,34 +224,19 @@ '%type' => $default_entity_type, ]); } - $form['default_entity_id'] = [ + $form['default_entity_id'] += [ '#type' => 'select', - '#title' => $this->t('Default entity'), - '#target_type' => $default_entity_type, '#options' => $options, '#empty_option' => $this->t('- None -'), - '#description' => $description, - '#weight' => 13, '#default_value' => $default_entity_id, - '#prefix' => '
', - '#suffix' => '
', - '#ajax' => [ - 'callback' => '::ajaxUpdateEntityId', - 'event' => 'change', - 'wrapper' => 'test-entity-wrapper', - 'progress' => ['type' => 'none'], - ], + '#description' => $description, ]; } } // No default entity type set, so just provide a wrapper for AJAX replace. else { - $form['default_entity_id'] = [ + $form['default_entity_id'] += [ '#type' => 'hidden', - '#target_type' => NULL, - '#weight' => 13, - '#prefix' => '
', - '#suffix' => '
', ]; }