Skip to content
Snippets Groups Projects
Commit 659f38a0 authored by project update bot's avatar project update bot Committed by Adam Bramley
Browse files

Issue #3433565 by dillix, manishvaity, acbramley: Automated Drupal 11...

Issue #3433565 by dillix, manishvaity, acbramley: Automated Drupal 11 compatibility fixes for ng_lightbox
parent fe580bd5
No related branches found
Tags 1.1.4
1 merge request!9Automated Project Update Bot fixes
Pipeline #396166 passed
lightboxed
\ No newline at end of file
################
# GitLabCI template for Drupal projects.
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification.
# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your
# pipelines automatically. However, you can modify this template if you have additional needs for your project.
# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/
################
# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/
# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml
include:
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
#
################
# Pipeline configuration variables are defined with default values and descriptions in the file
# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
# Uncomment the lines below if you want to override any of the variables. The following is just an example.
variables:
OPT_IN_TEST_PREVIOUS_MAJOR: 1
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_NEXT_MINOR: 1
_CSPELL_IGNORE_PATHS: 'README.md'
{
"name": "drupal/ng_lightbox",
"description": "A path based lightbox solution using CSS 3 properties.",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/ng_lightbox",
"support": {
"issues": "https://www.drupal.org/project/issues/ng_lightbox",
"source": "https://git.drupalcode.org/project/ng_lightbox"
}
}
name: NG Lightbox
description: A path based lightbox solution using CSS 3 properties.
type: module
core_version_requirement: ^8 || ^9 || ^10
core_version_requirement: ^10.3 || ^11
package: NG
configure: ng_lightbox.settings
dependencies:
......
services:
ng_lightbox:
class: Drupal\ng_lightbox\NgLightbox
arguments: ['@path.matcher', '@path_alias.manager', '@config.factory', '@router.admin_context']
arguments: ['@path.matcher', '@path_alias.manager', '@config.factory', '@router.admin_context', '@request_stack']
......@@ -3,6 +3,7 @@
namespace Drupal\ng_lightbox\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\ng_lightbox\NgLightbox;
......@@ -34,9 +35,15 @@ class NgLightboxSettingsForm extends ConfigFormBase {
* The factory for configuration objects.
* @param array $lightbox_renderers
* The lightbox renderers.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
* Typed config manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, array $lightbox_renderers) {
parent::__construct($config_factory);
public function __construct(
ConfigFactoryInterface $config_factory,
array $lightbox_renderers,
TypedConfigManagerInterface $typed_config_manager,
) {
parent::__construct($config_factory, $typed_config_manager);
$this->renderers = $lightbox_renderers;
}
......@@ -46,7 +53,8 @@ class NgLightboxSettingsForm extends ConfigFormBase {
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->getParameter('ng_lightbox_renderers')
$container->getParameter('ng_lightbox_renderers'),
$container->get('config.typed'),
);
}
......
......@@ -3,10 +3,11 @@
namespace Drupal\ng_lightbox;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\Core\Path\PathMatcherInterface;
use Drupal\Core\Routing\AdminContext;
use Drupal\Core\Url;
use Drupal\path_alias\AliasManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Provides a Service Class for NgLightbox.
......@@ -46,6 +47,13 @@ class NgLightbox {
*/
protected $adminContext;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* An array of paths that were already checked and their match status.
*
......@@ -66,17 +74,24 @@ class NgLightbox {
* The config factory so we can get the lightbox settings.
* @param \Drupal\Core\Routing\AdminContext $admin_context
* Provides a helper class to determine whether the route is an admin one.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
*/
public function __construct(PathMatcherInterface $path_matcher, AliasManagerInterface $alias_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context) {
public function __construct(
PathMatcherInterface $path_matcher,
AliasManagerInterface $alias_manager,
ConfigFactoryInterface $config_factory,
AdminContext $admin_context,
RequestStack $request_stack,
) {
$this->pathMatcher = $path_matcher;
$this->aliasManager = $alias_manager;
$this->config = $config_factory->get('ng_lightbox.settings');
$this->adminContext = $admin_context;
$this->requestStack = $request_stack;
}
/**
* Checks whether a give path matches the ng-lightbox path rules.
*
* This function checks both internal paths and aliased paths.
*
* @param \Drupal\Core\Url $url
......@@ -87,6 +102,8 @@ class NgLightbox {
*/
public function isNgLightboxEnabledPath(Url $url) {
$request = $this->requestStack->getCurrentRequest();
// No lightbox on external Urls.
if ($url->isExternal()) {
return FALSE;
......@@ -109,7 +126,7 @@ class NgLightbox {
}
// Remove the base path.
if ($base_path = \Drupal::request()->getBasePath()) {
if ($base_path = $request->getBasePath()) {
$path = substr($path, strlen($base_path));
}
......@@ -118,7 +135,7 @@ class NgLightbox {
return $this->matches[$path];
}
// Normalise the patterns as well so that they match the normalised paths.
// Normalize the patterns as well so that they match the normalized paths.
// Exit early if no enabled paths.
if (!$patterns = $this->config->get('patterns')) {
return FALSE;
......
......@@ -60,12 +60,12 @@ class NgLightboxTest extends KernelTestBase {
$this->assertLightboxEnabled(Link::fromTextAndUrl('Normal Path', $node->toUrl())->toString(TRUE)->getGeneratedLink());
// Create a second node and make sure it doesn't get lightboxed.
$secondnode = Node::create([
$second_node = Node::create([
'type' => 'page',
'title' => $this->randomString(),
]);
$secondnode->save();
$this->assertLightboxNotEnabled(Link::fromTextAndUrl('Second Path', $secondnode->toUrl())->toString(TRUE)->getGeneratedLink());
$second_node->save();
$this->assertLightboxNotEnabled(Link::fromTextAndUrl('Second Path', $second_node->toUrl())->toString(TRUE)->getGeneratedLink());
$this->assertLightboxNotEnabled(Link::fromTextAndUrl('Empty Path', Url::fromRoute('<nolink>'))->toString(TRUE)->getGeneratedLink());
}
......
......@@ -71,8 +71,9 @@ class NgLightboxTest extends UnitTestCase {
$config_factory->get(Argument::exact('ng_lightbox.settings'))->willReturn($config);
$admin_context = $this->prophesize('Drupal\Core\Routing\AdminContext');
$admin_context->isAdminRoute()->willReturn($is_admin_route);
$requestStack = $this->prophesize('Symfony\Component\HttpFoundation\RequestStack');
$lightbox = new NgLightbox($path_matcher->reveal(), $alias_manager->reveal(), $config_factory->reveal(), $admin_context->reveal());
$lightbox = new NgLightbox($path_matcher->reveal(), $alias_manager->reveal(), $config_factory->reveal(), $admin_context->reveal(), $requestStack->reveal());
return $lightbox;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment