Problem/Motivation
We found one issue linked to Style Guide module.
In database log, you can see next message: Theme hook link not found.
Problem is actually for all themes on the site, for example, Drupal core themes Seven and Bartik.
The problem actually only on the Style Guide pages.
Log message has Warning shortcut.
Screenshots attached to the bottom of the issue.
We found one item with this hook in:
/styleguide/src/Plugin/Styleguide/defaultStyleguide.php:692
And another usage found in:
/styleguide/src/Generator.php:168
Steps to reproduce:
1. Install clear Drupal 8.5.x-dev instance
2. Install module styleguide 8.x-1.x-dev
3. Go to the page /admin/appearance/styleguide/seven
4. Go to the page /admin/reports/dblog
5. Click on Warning message with title 'theme'
Proposed resolution
In Style Guide module need to delete hook 'link' from items because this hook not implemented in Drupal core theme registry.
Comment | File | Size | Author |
---|---|---|---|
#19 | styleguide_8.x-1.x-dev_theme_hook_link_not_found_19_2928676_D8.5.x-dev.patch | 1.72 KB | ysamoylenko |
seven.jpg | 99.7 KB | ysamoylenko | |
bartik.jpg | 120.25 KB | ysamoylenko |
Comments
Comment #2
ysamoylenko CreditAttribution: ysamoylenko commentedComment #3
ysamoylenko CreditAttribution: ysamoylenko commentedComment #4
ysamoylenko CreditAttribution: ysamoylenko commentedComment #5
ioana apetri CreditAttribution: ioana apetri at OPTASY commentedHello,
Please review my patch, I am not sure about it, because I can't reproduce the warning in DB log.
Thanks.
Comment #6
OleksiyHello. Thanks for the patch.
The styleguide_links is Styleguide theme hook. It used to display the page elements navigation menu, so we shouldn't remove it.
The issue comes from Generator (http://cgit.drupalcode.org/styleguide/tree/src/Generator.php?h=8.x-1.x#n168) where used this missed theme hook link. So the link generation in sentence method needs to be fixed to build it correctly.
Comment #7
ysamoylenko CreditAttribution: ysamoylenko commentedHello,
Please review my patch.
All elements on the Style Guide pages not changed.
In DB log no any warning messages from Style Guide module.
Thanks.
Comment #8
ysamoylenko CreditAttribution: ysamoylenko commentedComment #9
OleksiyYour patch fixed the warning messages, but the links are still not displaying on the StyleGuide page.
I think it's because of
'#url' => $link,
, the #url option requires Drupal\Url object (core/lib/Drupal/Core/Render/Element/Link.php)Comment #10
ysamoylenko CreditAttribution: ysamoylenko commentedHello,
Please review my new patch.
All elements on the Style Guide pages not changed.
Links are successfully rendered in Drupal messages if they are valid.
In DB log no any warning messages from Style Guide module.
Please check the patch on the Drupal 8.4.x or 8.5.x-dev version.
Module version 8.x-1.x-dev.
Thanks.
Comment #11
OleksiyThanks for the patch.
Please remove these extra empty lines
We should allow adding any kind of URL in the sentence. Looks like will be better to move \Drupal\Core\Url::fromUri($link) outside the sentence() method.
I mean we should create and pass this \Drupal\Core\Url object here, this way a user can create the Url object using any available method and pass it into $this->generator->sentence() method. Also, this link path shouldn't be translatable.
Comment #12
ysamoylenko CreditAttribution: ysamoylenko commentedThanks for the review.
Please say about behaviour for the link in this case.
Link must be set for the whole sentence or, must look like the original variant, the first word is a link, next part of the sentence is plain text?
Comment #13
OleksiyBehaviour stays the same as before.
Just instead of using the 'http://www.example.com' (string) in $this->generator->sentence('http://www.example.com') need to pass object (\Drupal\Core\Url) as argument.
Comment #14
ysamoylenko CreditAttribution: ysamoylenko commentedHello, I try to pass object Url with call it in method sentence
and changed taked param link to * @param \Drupal\Core\Url $link in /src/GeneratorInterface.php:110,
but URL class with method fromUri is returned only Url object and can not be converted to string inside implode function from sentence method in Generator class.
Also, link in sentence() method needed Link title from the first word in the generated sentence. I think it can with usage Link class, for example:
And additional I found that sentence() method taken as the link from another calls string or integer values as the link, for fix it needs to implement the filter in sentence method for not object values or refactor another call of the sentence() method.
In case if link is taken to string value we need to translate link title with usage
t()
function or use another way to markup link with string translation.
Could you say any another way to fix the link in messages if my thinks are not correct?
Comment #15
ysamoylenko CreditAttribution: ysamoylenko commentedNew patch attached to the bottom of the message.
Please check the patch on the Drupal 8.4.x or 8.5.x-dev version.
Module version 8.x-1.x-dev.
Please add to testing environment :
Drupal versions 8.4.x 8.5.x-dev and style guide module version 8.x-1.x.
Comment #16
OleksiyThe goal was to keep
'#path' => $link,
, just make the $link of \Drupal\Core\Url type, as the'#type' => 'link',
requires for the '#path' \Drupal\Core\Url value.No need to use the t() function here, we generate new sentence every time.
Comment #17
ysamoylenko CreditAttribution: ysamoylenko commentedI created a new patch. Please review it.
It keeps code structure from my first patch, but not call \Drupal\Core\Link class, this time to sentence() method comes \Drupal\Core\Url object from drupal_set_message() function in defaultStyleguide.php class. Sentence() method returns markup object in this case.
Comment #18
OleksiyPlease remove 2 extra spaces. All other code looks good now :)
Comment #19
ysamoylenko CreditAttribution: ysamoylenko commentedThe new patch uploaded to the top of the message. Please review it.
Thanks for reviewing my patches.
Comment #20
ysamoylenko CreditAttribution: ysamoylenko commentedComment #22
OleksiyThank you! The patch was committed.