Problem/Motivation

Hi,
On drupal, a link type field can be used to enter an internal or external url and mailto.

By default the resitution is done correctly, however ui_suite _dsfr declares the hook ui_suite_dsfr_preprocess_pattern_button & ui_suite_dsfr_preprocess_pattern_link & ui_suite_dsfr_preprocess_pattern_footer_menu which checks whether the url is internal or external in order to apply certain attributes.

Except that mailto doesn't work with the verification of UrlHelper::externalIsLocal() and results in the following error 500 when the url starts with mailto :

InvalidArgumentException: A path was passed when a fully qualified domain was expected. in Drupal\Component\Utility\UrlHelper::externalIsLocal() (line 305 of core/lib/Drupal/Component/Utility/UrlHelper.php).

ui_suite_dsfr_preprocess_pattern_button(Array, 'pattern_button', Array)
call_user_func_array('ui_suite_dsfr_preprocess_pattern_button', Array) (Line: 285)

Steps to reproduce

1) Add a link-type field to an entity
2) Map the field to the button pattern
3) Create a content and enter mailto:nam@exemple.fr in the link url field.
4) Display the result on the page
5) See the 500 error

Proposed resolution

I recommend adding a check to the conditional of the ui_suite_dsfr_preprocess_pattern_button hook, which will ignore urls starting with a "mailto:".

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Martygraphie created an issue. See original summary.

martygraphie’s picture

Title: The url field of the button pattern does not support mailto and causes a 500 error » The url field of the button/link pattern does not support mailto and causes a 500 error
Issue summary: View changes

martygraphie’s picture

Status: Active » Needs review
martygraphie’s picture

I'm adding a temporary patch so that the modification will work on version 1.0.0-beta4 (based on version 1.9 of the DSFR)

pdureau’s picture

Title: The url field of the button/link pattern does not support mailto and causes a 500 error » [beta6] The url field of the button/link pattern does not support mailto and causes a 500 error
Status: Needs review » Needs work

Hi Martygraphie,

Thanks for the MR.

Just a question, why not using UrlHelper::setAllowedProtocols()?

For information, those preprocess hooks are useful fow now and it is great you are fixing them, but they will not stay, because they are forbidden by SDC Core API, so by incoming UI Patterns 2.x.

pdureau’s picture

Status: Needs work » Reviewed & tested by the community

Just a question, why not using UrlHelper::setAllowedProtocols()?

Maybe because mailto protocol doesn't work with UrlHelper which expects :/ instead of just :

I will merge

  • pdureau committed 816bdb9a on 1.0.x
    Issue #3414096 by Martygraphie, pdureau: add mailto protocol support to...
pdureau’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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