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

Add possibility for query parameters in sulu link #6440

Merged

Conversation

exastion
Copy link
Contributor

@exastion exastion commented Dec 26, 2021

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets fixes #6418
Related issues/PRs #6418
License MIT
Documentation PR sulu/sulu-docs#692

What's in this PR?

This PR adds the possibility to use query parameters in the sulu-link tags.

To Do

  • Create a documentation PR

This commit changes the parsing of the `<sulu-link>` tag `href` in
a way that allows a query string to be present.
For that, `getUuidAndAnchorFromHref` got renamed to `getPartsFromHref`
and returns now an array containing: `uuid`, `anchor`, `query`.
Copy link
Member

@alexander-schranz alexander-schranz left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. We need to split the parts correctly first by # and then the first part by ? I added a comment and an example how to achieve this.

$query = null;
$anchor = null;

$hasQuery = strpos($href, '?');
Copy link
Member

Choose a reason for hiding this comment

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

@exastion Something like my.url/#hello?page=1 means that hello?page=1 is the value of the anchor and it still a valid anchor. This is as example used in Single Page Application and are valid anchors. Sulu example use this kind of special anchor for frontend navigation.

That's why its important first to split the string by # and then go with split the first part by ? and not the other way around. So there is no problem also from backward compatibility we are not allowed to change to seperate attributes and as said its not really required.

So the following examples should show you best how the end result should look like:

<uuid>?test=query#anchor

ID: <uuid>
query: test=query
anchor: anchor
<uuid>#anchor?test=query

ID: <uuid>
query: 
anchor: anchor?test=query
<uuid>?test=query

ID: <uuid>
query: test=query
anchor: 

See https://3v4l.org/j94IN#v7.2.34 how to correctly split the string. A ? is a valid symbol as part of the anchor so we first need to split by # and then split the part before the anchor by #.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not know about these specifics up to now, I even thought in the beginning, query and anchor would be the other way around.. Well you always learn :)
This made things also easier.

Copy link
Member

Choose a reason for hiding this comment

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

Also nice to know the #anchor is never send to a server its only available for the browser. So if your browser requests https://sulu.io/services/support#chat a request is only send to https://sulu.io/services/support and browsers is handling #chat to scroll to the correct part. Or a javascript library is handling the #anchor like its done in the sulu admin.

Copy link
Member

@alexander-schranz alexander-schranz left a comment

Choose a reason for hiding this comment

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

To run the failing tests you can use:

bin/runtests -i -t MarkupBundle

The -i is only required at first run.


$hrefParts = \explode('?', $hrefParts[0], 2);
Copy link
Member

Choose a reason for hiding this comment

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

Some tests seems to fail here not sure in which cases $hrefParts[0] can not exist.

https://github.com/sulu/sulu/runs/4657974922?check_suite_focus=true

@alexander-schranz alexander-schranz added the Feature New functionality not yet included in Sulu label Jan 8, 2022
@alexander-schranz alexander-schranz changed the title Enhancement/sulu link query parameter Add possibility for query parameters in sulu link Jan 8, 2022
@exastion
Copy link
Contributor Author

exastion commented Jan 8, 2022

What is the issue with the two Node tests?

@alexander-schranz
Copy link
Member

@exastion as you didn't change anything in the JS you can ignore them. Maybe some dependency changes did make them fail now. We will have a look at them in a separate pull request.

@alexander-schranz
Copy link
Member

Issue was found here: browserify/resolve#269. Hopefully we get quick a response from them so we can continue here.

@alexander-schranz
Copy link
Member

@chirimoya should we add the possibility to add query to the link content type and text editor link overlay?

@alexander-schranz alexander-schranz merged commit 0826064 into sulu:2.x Jan 24, 2022
@alexander-schranz
Copy link
Member

@exastion Thank you for the contribution. I did merge this part as it can be used as it's own. Do you want to work also on the text editor integration for the query? There is currently possible to define a anchor but query should also be possible:

https://github.com/sulu/sulu/blob/2.4.0/src/Sulu/Bundle/AdminBundle/Resources/js/containers/CKEditor5/plugins/InternalLinkPlugin/InternalLinkPlugin.js

@exastion
Copy link
Contributor Author

@alexander-schranz I'm not too familiar with react, but I will give it a try.

@exastion exastion deleted the enhancement/sulu-link-query-parameter branch January 24, 2022 12:15
@alexander-schranz
Copy link
Member

alexander-schranz commented Jan 24, 2022

@exastion it is mostly the same as for the anchor was done some time ago. The following pull reqest should help you to find the files: https://github.com/sulu/sulu/pull/6090/files which are effected. Thank you for giving it a try 👍

@exastion
Copy link
Contributor Author

@alexander-schranz I think I did all the necessary changes. However I am not able to test it.
I am not able to initialize the database to run the AdminBundle tests, as it always uses root with no password for the database, despite changing the .env file.
I also cannot test it in the browser, as I don't seem to be able to build the admin interface directly in the sulu repository.

@alexander-schranz
Copy link
Member

For the ckeditor the tests are in the frontend so you run them with npm:

npm install

# fix code style
npm run lint:js -- --fix
npm run lint:scss -- --fix

# run typechecks
npm run flow

# run tests
npm run test

You can also just open the new pull request there we also will see what in the CI will fail.

Still for completeness the backend tests which I think you did not needed to adjust something for the ckeditor you can change the database in the src/Sulu/Bundle/TestBundle/Resources/app/config/parameters.yml file which was created. To run tests use the bin/runtests -i -a script. Or a specific bundle bin/runtests -i -C -t AdminBundle. There is also --flags="--filters .." to add phpunit filter option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included in Sulu
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query parameters in <sulu-link> tag
2 participants