Fatal error: Class 'Drupal\module_name\DOMDocument' not found in /var/www/drupal/modules/module_name/src/form_xml.php on line 359
Any idea why Drupal cannot find DOMDocument class?
I want to execute a code when a form is submitted
public function submitForm(array &$form, FormStateInterface $form_state) {
// Find out what was submitted.
$form_field = $form_state->getValue('content_types');
foreach ($form_field as $key => $value){
if (!empty($value)){
$return = File::generate();
}
}
}
In case you are wondering, module_name is the name of my custom module.
File::generate() is a static method which contains the DOMDocument class
The code works fine when I use devel to execute it, so any idea why can't it find the DOMDocument class on form submit?
Seems to me as if the form blocks access to the DOMDocument class.
\DOMDocument
with the leading slash, or php will look in the current namespace$xml = new \DOMDocument();
but no luck.Fatal error: Class \DOMDocument' not found
?