- Issue created by @dariemlazaro
- Status changed to Postponed: needs info
over 1 year ago 12:59am 18 May 2023 - πΊπΈUnited States markdorison
@dariemlazaro Thanks for the report! This issue does not occur on rc1? I am reviewing the diff between rc1 and rc2 and nothing is jumping out at me that would be the likely culprit.
- Status changed to Needs review
over 1 year ago 8:17pm 18 May 2023 - π¨πΊCuba dariemlazaro Havana
I found the problem in src/Form/FormatConfigurationFormPdf.php line 218. It was caused by a translatable string with variables. Maybe a regression or merge conflict. It seems to use a substitution syntax, but I don't know it.
This is the diff:
'#title' => $this->t('PDF filename'), '#default_value' => $this->config('printable.settings') ->get('pdf_location'), '#description' => $this->t("Filename with its location can be entered. If left empty and Save the pdf option has been selected the generated filename defaults to the node's path.The .pdf extension will be appended automatically." . $token_help, $token_args), '#description' => $this->t("Filename with its location can be entered. If left empty and Save the pdf option has been selected the generated filename defaults to the node's path.The .pdf extension will be appended automatically. :token_help :token_args", [ ':token_help' => $token_help, ':token_args' => $token_args, ]), ]; if (function_exists('token_element_validate')) { $form['settings']['print_pdf_filename']['#element_validate'][] = 'token_element_validate';
My changes were to revert that change and add a line break to improve readability.
$form['settings']['print_pdf_filename'] = [ '#type' => 'textfield', '#title' => $this->t('PDF filename'), '#default_value' => $this->config('printable.settings') ->get('pdf_location'), '#description' => $this->t("Filename with its location can be entered. If left empty and Save the pdf option has been selected the generated filename defaults to the node's path.The .pdf extension will be appended automatically.</br>" . $token_help, $token_args), ];
I think it needs review, if that change was for compatibility issues with Drupal 10.
Patch provided - @markdorison opened merge request.
- πΊπΈUnited States markdorison
Hi @dariemlazaro,
Here is the documentation for theFormattableMarkup::placeholderFormat
. I wonder if this could be occurring in scenarios where$token_args
is an empty array?Could you test the change I made in MR33 to see if that resolves the issue?
- π¨πΊCuba dariemlazaro Havana
Hello @markdorison
I test the code from MR33 but causes a malformed output:Filename with its location can be entered. If left empty and Save the pdf option has been selected the generated filename defaults to the node's path.The .pdf extension will be appended automatically. This field supports tokens: 'container' --> <!-- BEGIN OUTPUT from 'core/modules/system/templates/container.html.twig' --> <div> <!-- THEME DEBUG --> <!-- THEME HOOK: 'token_tree_link' --> <!-- BEGIN OUTPUT from 'modules/contrib/token/templates/token-tree-link.html.twig' --> <a href="/drupal_site/token/tree?options=%7B%22token_types%22%3A%5B%22all%22%5D%7D&token=VntZh8KpVVl2BtCXlCOSSxVE2YDDDS2Y9ngz1JiCmGE" class="token-dialog use-ajax" data-dialog-type="dialog" data-dialog-options="{"dialogClass":"token-tree-dialog","width":600,"height":400,"position":{"my":"right bottom","at":"right-10 bottom-10"},"draggable":true,"autoResize":false}">Ojear comodines disponibles.</a> <!-- END OUTPUT from 'modules/contrib/token/templates/token-tree-link.html.twig' --> </div> <!-- END OUTPUT from 'core/modules/system/templates/container.html.twig' -->
It seems that the
:variable
when validated is formatted erroneously by validation or other reason. For example:token_help
only output@browse_tokens_link
removing the plain text string, also@browse_tokens_link
was not substituted. Instead using @token_help correctly renders the plaintext and @browse_tokens_link, but does not seem to replace it with $token_args either using :token_args or @token_args.When using @token_args the output is as follows:
Filename with its location can be entered. If left empty and Save the pdf option has been selected the generated filename defaults to the node's path.The .pdf extension will be appended automatically. This field supports tokens: @browse_tokens_link <!-- THEME DEBUG --> <!-- THEME HOOK: 'container' --> <!-- BEGIN OUTPUT from 'core/modules/system/templates/container.html.twig' --> <div> <!-- THEME DEBUG --> <!-- THEME HOOK: 'token_tree_link' --> <!-- BEGIN OUTPUT from 'modules/contrib/token/templates/token-tree-link.html.twig' --> <a href="/drupal_site/token/tree?options=%7B%22token_types%22%3A%5B%22all%22%5D%7D&token=VntZh8KpVVl2BtCXlCOSSxVE2YDDDS2Y9ngz1JiCmGE" class="token-dialog use-ajax" data-dialog-type="dialog" data-dialog-options="{"dialogClass":"token-tree-dialog","width":600,"height":400,"position":{"my":"right bottom","at":"right-10 bottom-10"},"draggable":true,"autoResize":false}">Ojear comodines disponibles.</a> <!-- END OUTPUT from 'modules/contrib/token/templates/token-tree-link.html.twig' --> </div> <!-- END OUTPUT from 'core/modules/system/templates/container.html.twig' -->
Then I changed this on line 209
$token_help = ' This field supports tokens: @browse_tokens_link';
to$token_help = ' This field supports tokens: ';
and this on line 220'@token_args' => implode(", ",$token_args),
to'@token_args' => $token_args["@browse_tokens_link"],
Resulting code:
$token_args = [ '@browse_tokens_link' => \Drupal::service('renderer')->render($build), ]; $token_help = ' This field supports tokens: '; } $form['settings']['print_pdf_filename'] = [ '#type' => 'textfield', '#title' => $this->t('PDF filename'), '#default_value' => $this->config('printable.settings') ->get('pdf_location'), '#description' => $this->t("Filename with its location can be entered. If left empty and Save the pdf option has been selected the generated filename defaults to the node's path.The .pdf extension will be appended automatically. @token_help @token_args", [ '@token_help' => $token_help, '@token_args' => $token_args["@browse_tokens_link"], ]), ]; if (function_exists('token_element_validate')) { $form['settings']['print_pdf_filename']['#element_validate'][] = 'token_element_validate'; }
- πΊπΈUnited States markdorison
@dariemlazaro I updated the MR with your suggestion. This should fix the error though I am unsure if this fulfills the original intention of what was trying to be achieved with this code. π€
- π¨πΊCuba dariemlazaro Havana
@markdorison The purpose of this code is to show the link to insert tokens in the field description and not as a form element. The use of
:variable
instead of@variable
sintax was to escape dangerous sentences in the "href" attribute of the link to the token popup, but maybe this module already escapes those values and when using:variable
sintax again it validates twice causing that rendering error. I agree that it needs review by the community and maintainers to reach consensus on what is the correct and safest way to display that link in the field description. - π¦πΊAustralia Nigel Cunningham Geelong
Perhaps we should just use the normal token element?
- Status changed to RTBC
over 1 year ago 4:59pm 11 July 2023 - π¨π¦Canada leducdubleuet Chicoutimi QC
I reviewed the commit 4d8c5c7a - Fix token_args rendering and it does not work. No error on the page but the token link is not functional.
With the complete patch printable-pdf2.patch in comment #6, all is well and the token link displays correctly.
Thank you!
- Status changed to Needs review
over 1 year ago 4:00pm 18 July 2023 - Open on Drupal.org βCore: 10.0.7 + Environment: PHP 8.1 & MySQL 8last update
over 1 year ago Waiting for branch to pass - πΊπΈUnited States markdorison
The patch in #6 is not applying cleanly for me. I have rerolled it if someone could take another look.
- Status changed to RTBC
over 1 year ago 4:33pm 18 July 2023 - π¨π¦Canada leducdubleuet Chicoutimi QC
I have tested the new patch 3361048-11.patch and it does not work work here on 3.0.0 and current dev.
But the patch printable-pdf2.patch in comment #6 still works well on 3.0.0. and current dev.
So the already reviewed patch is still valid, I believe we should hide the new one and commit printable-pdf2.patch if the maintainers agree that it is ok with the original intended purpose.
Thank you.
-
markdorison β
committed 3a12bead on 3.x
Issue #3361048 by markdorison, dariemlazaro, LeDucDuBleuet: Error on...
-
markdorison β
committed 3a12bead on 3.x
- Status changed to Fixed
over 1 year ago 4:40pm 18 July 2023 - π¨π¦Canada leducdubleuet Chicoutimi QC
This is great, thanks for committing this!
But since this is quite major, will there be a new official release including this fix?
Automatically closed - issue fixed for 2 weeks with no activity.