- Issue created by @Bohus Ulrych
I'm trying to create webform submission from external PHP script using bootstraped Drupal.
For bootstraped Drupal I'm using this code
define('DRUPAL_DIR', '/var/www/drupal/web');
set_include_path(get_include_path() . PATH_SEPARATOR . DRUPAL_DIR);
chdir(DRUPAL_DIR);
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
$requestStack = Drupal::service('request_stack')->push($request);
from https://www.drupal.org/project/drupal/issues/3243387 🐛 Argument 1 passed to Drupal\Core\Routing\RequestContext::fromRequest() must be an instance of Symfony\Component\HttpFoundation\Request, null given Closed: cannot reproduce
Then I'm trying to create submission as documented here https://www.drupal.org/docs/contributed-modules/webform/webform-cookbook... →
But I'm getting errors
Error: Call to undefined function Drupal\webform\Entity\base_path() in /var/www/drupal/web/modules/contrib/webform/src/Entity/WebformSubmission.php on line 855 #0 /var/www/drupal/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(87): Drupal\webform\Entity\WebformSubmission::preCreate()
This one I fixed with
require_once DRUPAL_DIR . '/core/includes/common.inc';
But I think that correct approach would be to replace
'uri' => preg_replace('#^' . base_path() . '#', '/', $current_request->getRequestUri()),
with
'uri' => preg_replace('#^' . $GLOBALS['base_path'] . '#', '/', $current_request->getRequestUri()),
Error: Undefined constant "Drupal\webform\Entity\DRUPAL_DISABLED" in /var/www/drupal/web/modules/contrib/webform/src/Entity/Webform.php on line 1164 #0 /var/www/drupal/web/modules/contrib/webform/src/Entity/Webform.php(979): Drupal\webform\Entity\Webform::getDefaultSettings()
fixed with
require_once DRUPAL_DIR . '/core/modules/system/system.module';
Maybe this could be solved by loading \Drupal::moduleHandler()->load('system'); in the webform files.
Thanks
Active
6.2
Code