0

I activated the Link module that is part of Drupal core. I want to add on the user profiles fields with links to social pages and limit the domain used in the link.

How can I add such restriction to the link field?

I also tried the Social Media Links Block and Field module, but it uses a third-party library for the icons and it does not suit me.

I would like to make the link form elements appear like in the following screenshot.

screenshot

1 Answer 1

3

I would do the following:

  1. Implement hook_field_widget_single_element_form_alter(), and add an #element_prefix key in front of the URL field with the domain. This will handle the display.

  2. Create a custom validation constraint that limits the URL element of the Link field, and add it to the field on the user (using method #2 on the linked page).

2
  • Thank you for your reply. Is there a method without a custom code ?
    – zoulou66
    Commented Apr 18, 2022 at 12:27
  • Not from me. Hopefully someone else may give you an alternative solution.
    – Jaypan
    Commented Apr 18, 2022 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.