0

I have site that has multiple external links. I need a way to edit them all at once. For example: I have a site www.example.com that has multiple external links like SOME-IP/getaccess, SOME-IP/getaccess/todolist etc. As the number of these external links is large, its extremely difficult to move a site to a new setup.

I am looking for a way to edit these external links at one place. like i want to change base url of external links. Something like to change SOME-IP/getaccess, SOME-IP/getaccess/todolist etc. TO SOME-OTHER-IP/getaccess, SOME-OTHER-IP/getaccess/todolist etc. so that all external links will work in a new setup.

I know this is something that many have experienced in websites with multiple external links.

I read read and read, only thing i come up with global variables in settingg.php but how to use these variables in existing modules. Or Is there a module that allow to edit all external links at once.

Thanks for all the support.

  • Where are the external links? From the Link module? In body fields? Other places? – mpdonadio Apr 19 '16 at 15:42
  • I added a link in my answer to the instructions for creating a global variable in your own module, so you dont need to edit the settings.php – DeveloperWeeks Apr 20 '16 at 14:05
1

This sounds like an unfortunate build decision coming back to hurt maintenance; that in itself is a common occurrence. One phrase I must repeat here is "if things dont go as you planned, you have had an experience." The issue that you have, at least in the school I went to, is called a Magic Number Unique values with unexplained meaning or multiple occurrences which could (preferably) be replaced with named constants

Now, solutions. If you just want to plaster on more code to resolve this, then look at the External Links module. This module adds javascript that checks every link on your site to see if they use the site's base url, and if not it adds an image to indicate the link goes elsewhere. You could modify this code (the joys of open source) to change the IP from the old to the new. This is what I would consider a weak solution. It gets the desired result but it adds more code and processing to the site, and doesn't truly fix the root issue.

A better method would be to define a site variable ( code example ) to hold the ip address and then go and edit all of the references to it throughout the entire site to use that variable instead. This works if all of the links are generated in php somewhere, and not just hard-coded in the body field of various nodes. The advantage here is, if that ip address changes again you only have to update the variable value. That can even be done with a drush vset.

Now, assuming these links are in node bodies and do not have the ability to use a php variable, you can get a similar result with a hook. I would still recommend setting the new ip in a variable. Then using a hook_node_view you can preg_replace the old ip address with the contents of the variable in the whole body field for any node. Or in other fields too, or only on nodes of if( in_array( $node->type, $target_types_array)) etc. This has the advantage of similar flexibility to the variable solution, but it does add extra processing like the javascript solution. However, it is a hook that does not need loops so it will not be much of an increase.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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