I have a WelcomeForm
inside my src
folder in my install profile. My install profile is located inside web/profiles folder and is correctly selected by default during install.
However, I added an install task (inside my business_profile.install
file) as so...
function business_profile_install_tasks_alter() {
$new_task['install_welcome'] = [
'display' => TRUE,
'type' => 'form',
'function' => '\Drupal\business_profile\src\Form\WelcomeForm'
];
But the installer shows an error -
InvalidArgumentException. Form \Drupal\business_profile\src\Form\WelcomeForm is not a valid form in... ->getFormId()
My WelcomeForm
extends FormBase and implements getFormId()
returning a valid string. Also implements buildForm()
and returns a valid $form array. Nothing wrong anywhere.And here's my WelcomeForm...
<?php
namespace Drupal\business_profile\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class WelcomeForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'business_profile_installer_welcome_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#title'] = $this->t('Welcome');
$form['actions'] = [
'#type' => 'actions'
];
$form['actions']['save'] = [
'#type' => 'submit',
'#value' => $this->t('Save and continue'),
'#button_type' => 'primary',
'#submit' => ['::submitForm'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('<front>');
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {}
}
And I can confirm the form is saved as web/profiles/business_profile/src/Form/WelcomeForm.php
What could possibly make Drupal installer not to see my Form then? Is this an autoload issue (just suspecting) - but I thought files in a selected install profile (distribution) are autoloaded?
Spent a few days on this, any help pls guys?