Hello there,

After upgrading drupal/anchor_link (1.7.0 => 2.1.0) on v8.8.2 PHP 7.3.8 logs show me following PHP Warnings:

Warning: Use of undefined constant ANCHOR_LINK_LIBRARY_PATH - assumed 'ANCHOR_LINK_LIBRARY_PATH' (this will throw an Error in a future version of PHP) in Drupal\anchor_link\Plugin\CKEditorPlugin\AnchorLink->getLibraryPath() (line 83 of /Users/robin-strasen/Documents/GitHub/geschke-hosting/web/modules/contrib/anchor_link/src/Plugin/CKEditorPlugin/AnchorLink.php)
Warning: Use of undefined constant ANCHOR_LINK_LIBRARY_PATH - assumed 'ANCHOR_LINK_LIBRARY_PATH' (this will throw an Error in a future version of PHP) in Drupal\anchor_link\Plugin\CKEditorPlugin\AnchorLink->getLibraryPath() (line 91 of /Users/robin-strasen/Documents/GitHub/geschke-hosting/web/modules/contrib/anchor_link/src/Plugin/CKEditorPlugin/AnchorLink.php)

Adding quotes to given var fixes this warning. Following patch can be used until this is fixed in one of the next releases.

Best

Comments

r81d3r created an issue. See original summary.

r81d3r’s picture

Assigned: r81d3r » Unassigned
joelpittet’s picture

Version: 8.x-2.1 » 8.x-2.x-dev
Priority: Normal » Critical
Status: Active » Needs review
StatusFileSize
new653 bytes

The patch is incorrect, the reason it's mentioning undefined is because it's defined in the anchor_link.install file which is only loaded in certain circumstances.

I did a quick test and moving it to the module file is more likely to be available in more circumstances.

This will likely need a new release.

joelpittet’s picture

Title: undefined constant ANCHOR_LINK_LIBRARY_PATH » Undefined constant ANCHOR_LINK_LIBRARY_PATH
StatusFileSize
new643 bytes

Also the file shouldn't be in the path name.

joelpittet’s picture

StatusFileSize
new2.03 KB

Also while debugging I noticed that

  1. The path returned is the filesystem path with DRUPAL_ROOT, not the URL's path which failed to load
  2. getLibraryPath gets called a few times so the result should be static cached
pookmish’s picture

I've just ran into this same issue. The patch works.

But personally i think a constant on the AnchorLink class would be more appropriate. Then the constant doesn't get added to the global scope and is only called when necessary.

joelpittet’s picture

I agree, would you like to roll that patch or should I?

joelpittet’s picture

StatusFileSize
new2.88 KB

Here's the Class constant replacement @pookmish

rajab natshah’s picture

Title: Undefined constant ANCHOR_LINK_LIBRARY_PATH » Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the better way of AnchorLink::LIBRARY_PATH

rajab natshah’s picture

Assigned: Unassigned » mohammed j. razem

Committed ... Thank you Joël for patching the better way!
Thanks, r81d3r for reporting and Mike for following up

rajab natshah’s picture

Assigned: mohammed j. razem » Unassigned
rajab natshah’s picture

Status: Needs review » Fixed
rajab natshah’s picture

Status: Fixed » Needs work
rajab natshah’s picture

Title: Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the better way of AnchorLink::LIBRARY_PATH » Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the better way of AnchorLinkLibrary::PATH final constant library
rajab natshah’s picture

Title: Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the better way of AnchorLinkLibrary::PATH final constant library » Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the better way of AnchorLinkLibrary::PATH final constant class library

  • RajabNatshah committed bf6f33a on 8.x-2.x
    Issue #3114343: Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the...
rajab natshah’s picture

Title: Fix undefined constant ANCHOR_LINK_LIBRARY_PATH with the better way of AnchorLinkLibrary::PATH final constant class library » Fix undefined constant ANCHOR_LINK_LIBRARY_PATH by removing constants

Removing constants as it will bring issues on

[Thu Feb 20 10:34:50.607183 2020] [php7:notice] [pid 6103] [client ::1:39044] Error: Class 'Drupal\\anchor_link\\Plugin\\CKEditorPlugin\\AnchorLink' not found in /var/www/html/test/d8c7/web/modules/contrib/anchor_link/anchor_link.install on line 19 #0 [internal function]: anchor_link_requirements('install')\n#1 /var/www/html/test/d8c7/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(392): call_user_func_array('anchor_link_req...', Array)\n#2 /var/www/html/test/d8c7/web/core/includes/install.inc(1048): Drupal\\Core\\Extension\\ModuleHandler->invoke('anchor_link', 'requirements', Array)

Trying to look at
https://git.drupalcode.org/project/drupal/commit/1edf15f

  • RajabNatshah committed 078239b on 8.x-2.x
    Issue #3114343: Fix undefined constant ANCHOR_LINK_LIBRARY_PATH by...

  • RajabNatshah committed 1cf244b on 8.x-2.x
    Issue #3114343: Fix undefined constant ANCHOR_LINK_LIBRARY_PATH by...
rajab natshah’s picture

Assigned: Unassigned » mohammed j. razem
Status: Needs work » Needs review
rajab natshah’s picture

Assigned: mohammed j. razem » Unassigned
rajab natshah’s picture

Status: Needs review » Fixed
rajab natshah’s picture

Planned to switch to use find from the LibrariesDirectoryFileFinder class
https://git.drupalcode.org/project/drupal/commit/1edf15f
When Drupal 8.9.x and Drupal 9.0.0 go out

But they still do have issues as getLibraryPath and getLibraryUrl. each will have it's used cases to check the phsical files and to call url link to images or + the origin Url -- removing language url ditection from the link to the image or js libraray.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.