diff --git a/fillpdf.api.php b/fillpdf.api.php index a4319d0567fab975e1da18f80c498ab2cd633591..fc8e1f5aa00307202973b6e9cbfbef07589a2b9e 100644 --- a/fillpdf.api.php +++ b/fillpdf.api.php @@ -5,11 +5,30 @@ * Hooks related to FillPDF module. */ +use Drupal\fillpdf\Form\FillPdfFormForm; + /** * @addtogroup hooks * @{ */ +/** + * Alter a FillPdfFormForm prior to building its edit form. + * + * This is triggered in FillPdfFormForm::form(). + * + * @param Drupal\fillpdf\Form\FillPdfFormForm $fillpdf_form_form + * The FillPdfFormForm object to alter. + */ +function hook_fillpdf_form_form_pre_form_build_alter(FillPdfFormForm $fillpdf_form_form): void { + // Set the default entity type for any FillPDF form to 'webform'. + $fillpdf_form = $fillpdf_form_form->getEntity(); + $default_entity_type = $fillpdf_form->getDefaultEntityType(); + if (!$default_entity_type) { + $fillpdf_form->set('default_entity_type', 'webform')->save(); + } +} + /** * Alter the $context in HandlePdfController::populatePdf(). * diff --git a/src/Form/FillPdfFormForm.php b/src/Form/FillPdfFormForm.php index a9dd549e66461c0542900851adfd649a0fe776a9..86539aded1d89960dc0f746cd73509e21a74f454 100644 --- a/src/Form/FillPdfFormForm.php +++ b/src/Form/FillPdfFormForm.php @@ -144,6 +144,9 @@ class FillPdfFormForm extends ContentEntityForm { * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { + // Create hook_fillpdf_form_form_pre_form_build_alter(). + $this->moduleHandler->alter('fillpdf_form_form_pre_form_build', $this); + $form = parent::form($form, $form_state); /** @var \Drupal\fillpdf\FillPdfFormInterface $fillpdf_form */