diff --git a/ng_lightbox.info.yml b/ng_lightbox.info.yml index e601c6e..1696a87 100644 --- a/ng_lightbox.info.yml +++ b/ng_lightbox.info.yml @@ -2,6 +2,7 @@ name: NG Lightbox description: A path based lightbox solution using CSS 3 properties. type: module core: 8.x +core_version_requirement: '^8 || ^9' package: NG configure: ng_lightbox.settings diff --git a/ng_lightbox.services.yml b/ng_lightbox.services.yml index 96b1564..4212e6f 100644 --- a/ng_lightbox.services.yml +++ b/ng_lightbox.services.yml @@ -1,4 +1,4 @@ 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'] diff --git a/src/NgLightbox.php b/src/NgLightbox.php index 874a0ff..f0342fd 100644 --- a/src/NgLightbox.php +++ b/src/NgLightbox.php @@ -3,13 +3,14 @@ namespace Drupal\ng_lightbox; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Path\AliasManagerInterface; +use Drupal\path_alias\AliasManagerInterface; use Drupal\Core\Path\PathMatcherInterface; use Drupal\Core\Routing\AdminContext; -use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Url; -use Symfony\Component\HttpFoundation\Request; +/** + * Provides a Service Class for NgLightbox. + */ class NgLightbox { /** @@ -18,21 +19,29 @@ class NgLightbox { const DEFAULT_MODAL = 'drupal_modal'; /** + * Provides an interface for URL path matchers. + * * @var \Drupal\Core\Path\PathMatcherInterface */ protected $pathMatcher; /** - * @var \Drupal\Core\Path\AliasManagerInterface + * Find an alias for a path and vice versa. + * + * @var \Drupal\path_alias\AliasManagerInterface */ protected $aliasManager; /** + * Defines the immutable configuration object. + * * @var \Drupal\Core\Config\ImmutableConfig */ protected $config; /** + * Provides a helper class to determine whether the route is an admin one. + * * @var \Drupal\Core\Routing\AdminContext */ protected $adminContext; @@ -49,10 +58,14 @@ class NgLightbox { * * @param \Drupal\Core\Path\PathMatcherInterface $path_matcher * Patch matcher services for comparing the lightbox patterns. - * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager + * @param \Drupal\path_alias\AliasManagerInterface $alias_manager * Alias manager so we can also test path aliases. + * The Path Alias core subsystem has been moved to the "path_alias" module + * [https://www.drupal.org/node/3092086]. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * 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. */ public function __construct(PathMatcherInterface $path_matcher, AliasManagerInterface $alias_manager, ConfigFactoryInterface $config_factory, AdminContext $admin_context) { $this->pathMatcher = $path_matcher; @@ -107,7 +120,7 @@ class NgLightbox { // Normalise the patterns as well so they match the normalised paths. $patterns = strtolower($this->config->get('patterns')); - // Check for internal paths first which is much quicker than the alias lookup. + // Check for internal paths first which is much quicker than alias lookup. if ($this->pathMatcher->matchPath($path, $patterns)) { $this->matches[$path] = TRUE; } diff --git a/src/NgLightboxPass.php b/src/NgLightboxPass.php index 7dca32e..ef1e69e 100644 --- a/src/NgLightboxPass.php +++ b/src/NgLightboxPass.php @@ -1,10 +1,5 @@ getDefinition($id); diff --git a/src/Tests/NgLightboxTest.php b/src/Tests/NgLightboxTest.php index b0a9e44..20c54f4 100644 --- a/src/Tests/NgLightboxTest.php +++ b/src/Tests/NgLightboxTest.php @@ -1,10 +1,5 @@ installSchema('system', ['router', 'url_alias']); + // $this->installSchema('system', ['router', 'url_alias']); \Drupal::service('router.builder')->rebuild(); $this->installEntitySchema('node'); $this->installEntitySchema('user'); - $this->installSchema('node', ['node_access']); + // $this->installSchema('node', ['node_access']); $this->installConfig(['ng_lightbox']); // Create the node type. @@ -49,15 +46,16 @@ class NgLightboxTest extends KernelTestBase { // Test the patterns are enabled on links as expected. $node = Node::create(['type' => 'page', 'title' => $this->randomString()]); $node->save(); - $config = \Drupal::configFactory()->getEditable('ng_lightbox.settings'); - $config->set('patterns', $node->toUrl())->save(); + $value_patterns = $node->toUrl()->toString(); + $config = \Drupal::configFactory()->getEditable('ng_lightbox.settings') + ->set('patterns', $value_patterns) + ->save(); $this->assertLightboxEnabled(Link::fromTextAndUrl('Normal Path', $node->toUrl())); // Create a second node and make sure it doesn't get lightboxed. - $node = Node::create(['type' => 'page', 'title' => $this->randomString()]); - $node->save(); - $this->assertLightboxNotEnabled(Link::fromTextAndUrl('Normal Path', $node->toUrl())); - + $secondnode = Node::create(['type' => 'page', 'title' => $this->randomString()]); + $secondnode->save(); + $this->assertLightboxNotEnabled(Link::fromTextAndUrl('Second Path', $secondnode->toUrl())); // @TODO, these were in D7 but in D8, I can't see how you can even generate // a link with such a format so maybe it isn't needed at all? @@ -74,8 +72,8 @@ class NgLightboxTest extends KernelTestBase { * The rendered link. */ protected function assertLightboxEnabled($link) { - $this->assertContains('use-ajax', $link); - $this->assertContains('data-dialog-type', $link); + $this->assertStringContainsString('use-ajax', $link->toString()); + $this->assertStringContainsString('data-dialog-type', $link->toString()); } /** @@ -85,48 +83,8 @@ class NgLightboxTest extends KernelTestBase { * The rendered link. */ protected function assertLightboxNotEnabled($link) { - $this->assertNotContains('use-ajax', $link); - $this->assertNotContains('data-dialog-type', $link); - } - - /** - * Asserts a string does exist in the haystack. - * - * @param string $needle - * The string to search for. - * @param string $haystack - * The string to search within. - * @param string $message - * The message to log. - * - * @return bool - * TRUE if it was found otherwise FALSE. - */ - protected function assertContains($needle, $haystack, $message = '') { - if (empty($message)) { - $message = t('%needle was found within %haystack', ['%needle' => $needle, '%haystack' => $haystack]); - } - return $this->assertTrue(stripos($haystack, $needle) !== FALSE, $message); - } - - /** - * Asserts a string does not exist in the haystack. - * - * @param string $needle - * The string to search for. - * @param string $haystack - * The string to search within. - * @param string $message - * The message to log. - * - * @return bool - * TRUE if it was not found otherwise FALSE. - */ - protected function assertNotContains($needle, $haystack, $message = '') { - if (empty($message)) { - $message = t('%needle was not found within %haystack', ['%needle' => $needle, '%haystack' => $haystack]); - } - return $this->assertTrue(stripos($haystack, $needle) === FALSE, $message); + $this->assertNotContains('use-ajax', $link->toRenderable()); + $this->assertNotContains('data-dialog-type', $link->toRenderable()); } } diff --git a/src/Tests/NgLightboxWebTest.php b/src/Tests/NgLightboxWebTest.php index ec989bc..20e4f5b 100644 --- a/src/Tests/NgLightboxWebTest.php +++ b/src/Tests/NgLightboxWebTest.php @@ -1,10 +1,5 @@ prophesize('Drupal\Core\Path\PathMatcherInterface'); - $alias_manager = $this->prophesize('Drupal\Core\Path\AliasManagerInterface'); + // The Path Alias core subsystem has been moved to the "path_alias" module. + $alias_manager = $this->prophesize('Drupal\path_alias\AliasManagerInterface'); $config_factory = $this->prophesize('Drupal\Core\Config\ConfigFactoryInterface'); $config = $this->prophesize('Drupal\Core\Config\ImmutableConfig'); $config->get(Argument::exact('skip_admin_paths'))->willReturn($skip_admin_paths);