Skip to content

Instantly share code, notes, and snippets.

@eiriksm
Created November 2, 2014 15:14
Show Gist options
  • Save eiriksm/76861b8115e9be0761a7 to your computer and use it in GitHub Desktop.
Save eiriksm/76861b8115e9be0761a7 to your computer and use it in GitHub Desktop.
Fixing descriptions
<?php
/**
* Implements hook_webform_component_presave().
*/
function mymodule_webform_component_presave(&$component) {
// Maybe I should do some more robust checking here, but this is a simple site
// and the body description clearly states how to format lines with links.
// Also, remember if you have other use cases for the webform, you should
// check that this is actually a webform created by above code!
if (strpos($component['name'], '(http') > -1) {
// Take the URL out of the name of the component.
$name = substr($component['name'], 0, strpos($component['name'], '(http'));
// Add animated gif link as description.
$component['extra']['description'] = l(t('View animated gif with @name', array(
'@name' => $name)), substr($component['name'], strpos($component['name'], 'http'), -2
));
// Set name to the new name (without the URL).
$component['name'] = $name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment