I'm a site administrator/content manager who wants to add functionality to a Drupal 8 site. I do NOT have a background in development (though I can make small modifications to code).

I am creating a product review site which reviews a certain kind of consumer product. The review form has a field for link to one particular ecommerce site. (not amazon.com, but like amazon).

This ecommerce site runs an affiliate marketing program which allows me to earn affiliate fees if my referral results in a sale.

I need all input of user URLs to append the code for my affiliate marketing account at the end of the URL ie. ,

One field in this review form will be othercommercesiteURL

When the user inputs http://www.othercommercesite.com/product3153.html into the form, I want the data to be stored (and displayed) as http://www.othercommercesite.com/product3153.html?ref=myaffiliateaccount.

Ideally, I'd need to check first if the user input URL doesn't already include the affiliate suffix, but I'd be happy with a way just to append this suffix. Because the URL will inputted in a form field labeled "Othercommercesite.com" I know the URL's are all going to go to this site.

How to accomplish this? Is there anything in Drupal 8 that already have this functionality (or something similar)?

  • 1
    A site builder way to do this would be to create a view and override the field output for the field. Set the href to the value and then append the referral query parameter to it. This would work if you display these fields via the view from now on.
    – mradcliffe
    Commented Oct 10, 2016 at 16:54
  • 1
    I reworded my original question to avoid making it seem as though I wanted responders to recommend something. This is NOT an opinion-based question, but a request for a technical solution and/or technical information about available modules. Therefore, I don't believe there is any good reason to mark it on hold as "off-topic." Commented Oct 10, 2016 at 17:57
  • 1
    No idea why this question is closed. You could achieve this by making a custom module using a hook on user input - probably hook_form_alter. This related question might help: drupal.stackexchange.com/questions/23411/… Alternatively, you could probably get what you want using the module drupal.org/project/rewrite_field or a similar module - what you're looking to do in drupal-speak is alter the content of an entity field after input Commented Dec 7, 2016 at 12:49
  • user568458 this was very helpful. (I actually put off working on this problem until this week, so it was timely also!) Commented Dec 12, 2016 at 0:37


Browse other questions tagged or ask your own question.