Score:0

How to add the domain to the Link field?

cn flag

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

Score:3
de flag

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).

cn flag
Thank you for your reply. Is there a method without a custom code ?
Jaypan avatar
de flag
Not from me. Hopefully someone else may give you an alternative solution.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.