Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update twig + fix #1019 change content language url #1022

Merged
merged 170 commits into from
Mar 11, 2021

Conversation

kouralex
Copy link
Contributor

@kouralex kouralex commented Jul 1, 2020

This PR firstly updates Twig to 2.12.x so that a better whitespace control is in use, see https://twig.symfony.com/doc/2.x/templates.html#whitespace-control for more information. Then, utilize that to break down one-liners into multiple lines so that errors can be more easily found and corrected.

Additionally, on the front page, only clang-supported vocabularies are referred to by the clang parameter.

Finally, remove some JavaScript code related to cookies in favor of Twig code and fix an issue with duplicate anylang=on parameter-key setting.

Fixes #1019, addresses #918

@kouralex kouralex requested a review from joelit July 1, 2020 22:03
@sonarcloud
Copy link

sonarcloud bot commented Jul 1, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Jul 1, 2020

Codecov Report

Merging #1022 (b0f4bfe) into master (8e09706) will increase coverage by 7.58%.
The diff coverage is 67.92%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1022      +/-   ##
============================================
+ Coverage     60.32%   67.91%   +7.58%     
+ Complexity     1593     1583      -10     
============================================
  Files            32       32              
  Lines          4429     3890     -539     
============================================
- Hits           2672     2642      -30     
+ Misses         1757     1248     -509     
Impacted Files Coverage Δ Complexity Δ
controller/RestController.php 13.02% <0.00%> (+1.57%) 194.00 <0.00> (+5.00)
model/GlobalConfig.php 89.62% <0.00%> (+2.46%) 51.00 <0.00> (ø)
model/SkosmosTurtleParser.php 100.00% <ø> (+45.16%) 1.00 <0.00> (-17.00) ⬆️
controller/WebController.php 16.77% <14.28%> (+1.78%) 84.00 <10.00> (+1.00)
controller/Honeypot.php 48.00% <55.55%> (+1.84%) 12.00 <12.00> (+1.00)
model/Concept.php 80.95% <100.00%> (+1.14%) 197.00 <0.00> (-1.00) ⬆️
model/ConceptProperty.php 100.00% <100.00%> (+3.70%) 20.00 <1.00> (+1.00)
model/ConceptPropertyValue.php 86.74% <100.00%> (-1.21%) 47.00 <0.00> (ø)
model/DataObject.php 77.50% <100.00%> (+1.89%) 22.00 <0.00> (-1.00) ⬆️
model/Model.php 83.68% <100.00%> (+2.15%) 105.00 <0.00> (ø)
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e09706...b0f4bfe. Read the comment docs.

kouralex and others added 20 commits July 2, 2020 13:01
The `results` field, which contains the search results, was incorrectly called `vocabularies` in the swagger spec - looks like a copy-paste error.
…uage

fix #1018 by explicitly declaring the UI locale in getDate()
Fix error in swagger spec for search method return value
…mappings

remove dead code: the renderPropertyMappingValues function is never used
…rties

Add HTML classes for properties so they can be targeted in JS and CSS
@osma osma requested review from osma and removed request for joelit March 10, 2021 12:17
@osma osma self-assigned this Mar 10, 2021
@osma
Copy link
Member

osma commented Mar 10, 2021

Please note that the Twig update part has now already been done on the master branch.

Could you please rebase this on current master then, @kouralex? It would make it easier to see the actual changes remaining to be merged.

Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling a bit with this PR...

First the apparent problem: there are two merge conflicts against master (see detailed comments) and they should be fixed before this can even be properly tested.

Second, I have the feeling again that this PR tries to do too many things at once. It's not crystal clear why it has to be like that. It would be better to fix problems individually in very small increments. That makes it easier to review, and also to backtrack if new problems are detected later.

Third, the PR makes it apparent that we are constructing very complex URLs using Twig expressions. This seems wrong-headed, and we should try to do that in PHP code instead, using the link_url filter if possible and if not, perhaps extending it and/or adding new similar filters. This isn't directly the fault of this PR though, the problem has existed before and this just makes it more visible.

composer.json Outdated Show resolved Hide resolved
view/topbar.twig Outdated Show resolved Hide resolved
{% endfor %}
{% else %}
{% for langcode in lang_list %}
<li><a href="{{ request.lang }}/{{ request.page }}?clang={{langcode}}{% if term %}&q={{ term }}{% endif %}{% if vocabs %}&vocabs={{ vocabs }}{% endif %}" class="lang-button" hreflang="{{ langcode }}">{{ langcode | lang_name(request.lang) }}</a></li>
<li><a href="{{ request.lang }}/{{ request.page -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't help feeling that this is the wrong way to construct URLs in Twig templates - we should use the link_url filter or something like it to construct the complex URLs in PHP code, not here with Twig expressions. This wasn't as apparent before this PR, since all the complexity was "hidden" within very long lines in the Twig templates!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is how it was already done in code. I only refactored it.

view/headerbar.twig Show resolved Hide resolved
@@ -536,9 +536,6 @@ $(function() { // DOCUMENT READY

// Setting the language parameters according to the clang parameter or if that's not possible the cookie.
var search_lang = (content_lang !== '' && !getUrlParams().anylang && vocab !== '') ? content_lang : readCookie('SKOSMOS_SEARCH_LANG');
if (vocab === '' && readCookie('SKOSMOS_SEARCH_LANG') === 'anything') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite understand why the cookie handling was moved from JS to PHP/Twig code. I'm sure there's a good reason but it wasn't apparent from the PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Twig is processed before it is handled to the user, JS afterwards. One can see changes happening after the page has loaded - it is not ready for use. I think this is also for better accessibility, don't you think so, too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right. Can you explain how this is different from a user perspective? Is there some user-facing problem with the JS approach that is fixed here?

@sonarcloud
Copy link

sonarcloud bot commented Mar 10, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kouralex
Copy link
Contributor Author

@osma I did a rebase. You may now test this PR with the usual procedure. One can look https://github.com/NatLibFi/Skosmos/compare/issue1019-fix-change-content-language-url for code changes - the rebase made all commits to be applied to this branch.

@osma
Copy link
Member

osma commented Mar 11, 2021

Thanks for the rebase. Yeah, something went awry there - the diff is now huge. Thanks for the link to the branch diff.

@osma osma marked this pull request as ready for review March 11, 2021 15:42
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I understand everything in this PR, but it fixes the original problem, and contains many improvements, so it's OK to merge. If any issues show up later we can fix them in new PRs.

@osma osma merged commit c1a339b into master Mar 11, 2021
@osma osma deleted the issue1019-fix-change-content-language-url branch March 11, 2021 15:44
@kouralex kouralex added this to the 2.10 milestone Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL parameter uri used when there is no need
6 participants