Skip to content
Snippets Groups Projects

Resolve #3473023 "Fix the issues"

1 file
+ 20
8
Compare changes
  • Side-by-side
  • Inline
@@ -18,6 +18,7 @@ use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\navigation_extra\NavigationExtraPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
@@ -73,6 +74,13 @@ class VersionPlugin extends NavigationExtraPluginBase {
*/
protected string $installProfile;
/**
* The request stack used to get the current request.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
private RequestStack $requestStack;
/**
* Constructs a \Drupal\Component\Plugin\PluginBase object.
*
@@ -108,6 +116,8 @@ class VersionPlugin extends NavigationExtraPluginBase {
* The file system service.
* @param string $install_profile
* The name of the install profile.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack used to determine the current time.
*/
public function __construct(
array $configuration,
@@ -126,6 +136,7 @@ class VersionPlugin extends NavigationExtraPluginBase {
MenuLinkManagerInterface $menu_link_manager,
FileSystemInterface $file_system,
string $install_profile,
RequestStack $request_stack,
) {
parent::__construct(
$configuration,
@@ -146,6 +157,7 @@ class VersionPlugin extends NavigationExtraPluginBase {
$this->menuLinkManager = $menu_link_manager;
$this->fileSystem = $file_system;
$this->installProfile = $install_profile;
$this->requestStack = $request_stack;
}
/**
@@ -168,7 +180,8 @@ class VersionPlugin extends NavigationExtraPluginBase {
$container->get('extension.list.module'),
$container->get('plugin.manager.menu.link'),
$container->get('file_system'),
$container->getParameter('install_profile')
$container->getParameter('install_profile'),
$container->get('request_stack')
);
}
@@ -751,7 +764,7 @@ class VersionPlugin extends NavigationExtraPluginBase {
$value = $_SERVER[$header] ?? '';
$pattern = !empty($environment['source']['pattern']) ? $environment['source']['pattern'] : '/no-valid-pattern/';
return preg_match($pattern, $value, $matches) ? $environment : [];
return preg_match($pattern, $value) ? $environment : [];
}
/**
@@ -763,7 +776,7 @@ class VersionPlugin extends NavigationExtraPluginBase {
$value = getenv($variable) ?? '';
$pattern = !empty($environment['source']['pattern']) ? $environment['source']['pattern'] : '/no-valid-pattern/';
return preg_match($pattern, $value, $matches) ? $environment : [];
return preg_match($pattern, $value) ? $environment : [];
}
/**
@@ -772,11 +785,10 @@ class VersionPlugin extends NavigationExtraPluginBase {
public function getEnvironmentFromDomain($environment) : array {
// @todo Use dependency injection for this.
// @phpstan-ignore-next-line
$value = \Drupal::request()->getHost();
$value = $this->requestStack->getCurrentRequest()->getHost();
$pattern = !empty($environment['source']['pattern']) ? $environment['source']['pattern'] : '/no-valid-pattern/';
return preg_match($pattern, $value, $matches) ? $environment : [];
return preg_match($pattern, $value) ? $environment : [];
}
/**
@@ -805,8 +817,8 @@ class VersionPlugin extends NavigationExtraPluginBase {
$this->addLink('navigation.version', [
'url' => $url,
'route_name' => $route_name,
'title' => $this->getVersionFormatted('title'),
'description' => $this->getVersionFormatted('description') ?: $this->getVersionFormatted('title'),
'title' => $this->getVersionFormatted(),
'description' => $this->getVersionFormatted('description') ?: $this->getVersionFormatted(),
'weight' => -11,
'options' => [
'attributes' => [
Loading