Site crashes when I require a directory for my module [on hold]

02/07/2018


I have a custom php code that lives in my_code.php file. In the begining of the file there is the line

 require __DIR__ . '/vendor/autoload.php';

The code works perfectly if I visit mysite/my_code.php but I need to be executed when a form is submited. So I placed the code in a form alter hook and the line

require __DIR__ . '/vendor/autoload.php';

in the beggining of my_custom_module.module file like this

<?php
require __DIR__ . '/vendor/autoload.php';
use DrupalnodeEntityNode;
use DrupalCoreFormFormStateInterface;
use DrupalCoreEntityEntityTypeInterface;

function my_custom_module_form_alter(&$form, $form_state, $form_id)
{.....my code....}

but the site crashes… Why does the code

require __DIR__ . '/vendor/autoload.php';

work in a php file but not in my module’s .module file? What am I doing wrong?

The message from my site’s logs is

mod_fcgid: stderr: PHP Fatal error: require(): Failed opening required
'/var/www/vhosts/my_site.com/httpdocs/modules/custom/my_module/vendor
/autoload.php' (include_path='.:/usr/share/pear/:') in /var/www/vhosts
/my_site.com/httpdocs/modules/custom/my_module/my_module.module on line 2

What should I change?

قالب وردپرس