Skip to content
Snippets Groups Projects
Commit ae332b49 authored by ambient.impact's avatar ambient.impact
Browse files

Issue #3361318: Fixes TargetModuleBuilder fatal error on Drupal 10.

parent 0c0d658a
Branches
Tags 1.0.5
1 merge request!22Issue #3361318: Fixes TargetModuleBuilder fatal error on Drupal 10.
...@@ -8,6 +8,7 @@ use Drupal\config_enforce\ConfigEnforceHelperTrait; ...@@ -8,6 +8,7 @@ use Drupal\config_enforce\ConfigEnforceHelperTrait;
use Drupal\Core\Config\InstallStorage; use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Extension\MissingDependencyException; use Drupal\Core\Extension\MissingDependencyException;
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\config_enforce\ConfigEnforcer; use Drupal\config_enforce\ConfigEnforcer;
...@@ -37,11 +38,19 @@ class TargetModuleBuilder { ...@@ -37,11 +38,19 @@ class TargetModuleBuilder {
// An instance of the Drupal file system service. // An instance of the Drupal file system service.
protected $fileSystem; protected $fileSystem;
/**
* The Drupal renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected RendererInterface $renderer;
/** /**
* A basic constructor method. * A basic constructor method.
*/ */
public function __construct() { public function __construct() {
$this->fileSystem = \Drupal::service('file_system'); $this->fileSystem = \Drupal::service('file_system');
$this->renderer = \Drupal::service('renderer');
} }
/** /**
...@@ -313,15 +322,20 @@ class TargetModuleBuilder { ...@@ -313,15 +322,20 @@ class TargetModuleBuilder {
*/ */
protected function getInfoFileContents() { protected function getInfoFileContents() {
$template = \Drupal::service('extension.list.module')->getPath('config_enforce_devel') . '/templates/info.yml.twig'; $template = \Drupal::service('extension.list.module')->getPath('config_enforce_devel') . '/templates/info.yml.twig';
// Cast to string since twig_render_template returns a Markup object.
return (string) \Drupal::service('twig') /** @var array Render array for the extension .info.yml contents. */
->loadTemplate($template) $renderArray = [
->render([ '#type' => 'inline_template',
'name' => $this->getName(), '#template' => \file_get_contents($template),
'#context' => [
'name' => $this->getName(),
'description' => $this->getDescription(), 'description' => $this->getDescription(),
// Needed to prevent notices when Twig debugging is enabled. ],
'theme_hook_original' => 'not-applicable', ];
]);
// Cast to a string since this an object implementing
// \Drupal\Component\Render\MarkupInterface
return (string) $this->renderer->renderPlain($renderArray);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment