nabo Posted December 20, 2019 Share Posted December 20, 2019 Hello quite strange request! I've got two fields (inside a Profields: Textarea and Profields: Table) filled with generated URL. I would lock them but would also like to have the link instead of the flat string. Any idea? Link to comment Share on other sites More sharing options...
bernhard Posted December 20, 2019 Share Posted December 20, 2019 // site/ready.php $wire->addHookAfter("Inputfield::render", function($event) { $field = $event->object; if($field->name !== "yourfield") return; $event->return = "<a href='foo/bar'>Your link</a>"; }); You could use one of the Runtime Markup Inputfields or something like the hook above (untested - just an example to get you started). 1 Link to comment Share on other sites More sharing options...
nabo Posted December 20, 2019 Author Share Posted December 20, 2019 41 minutes ago, bernhard said: // site/ready.php $wire->addHookAfter("Inputfield::render", function($event) { $field = $event->object; if($field->name !== "yourfield") return; $event->return = "<a href='foo/bar'>Your link</a>"; }); You could use one of the Runtime Markup Inputfields or something like the hook above (untested - just an example to get you started). Hi @bernhard and thanks. This would work perfectly in a textfield but unfortunately I have these fields inside a Profields: Textareas and Profields: Table. How can I hook them? Link to comment Share on other sites More sharing options...
elabx Posted December 20, 2019 Share Posted December 20, 2019 From the looks of the source, at least Profields table doesn't seem to be very hookable at that detail (it's creating the markup concatenating strings), you could only hook on the inputfield render method and that includes the whole markup for the table field. I'd try with some custom javascript. Textareas does seem to trigger the Inputfield render method, so I'd give it a shot with @bernhard's hook. Link to comment Share on other sites More sharing options...
adrian Posted December 20, 2019 Share Posted December 20, 2019 This is an example of something I do with Profields Table for replacing Twilio message and error codes with links to the entry in the logs on the Twilio site. You should be able to adapt to your needs. // link SID and error code columns in User message tables to the Twilio log entry $this->wire()->addHookAfter('InputfieldTable::render', function($event) { if(!in_array($event->object->name, array('received_messages', 'incoming_messages', 'queued_messages', 'undelivered_messages', 'failed_messages'))) return; $text = $event->return; if(preg_match_all("/<td>(S|M)M(.*?)<\/td>/", $text, $matches)) { foreach($matches[0] as $match) { $sid = str_replace(array('<td>', '</td>'), '', $match); $text = str_replace($match, '<td><a href="https://www.twilio.com/console/sms/logs/'.$sid.'">'.$sid.'</a></td>', $text); } } if(preg_match_all("/<td>([0-9]{1,})<\/td>/", $text, $matches)) { foreach($matches[0] as $match) { $errCode = str_replace(array('<td>', '</td>'), '', $match); $text = str_replace($match, '<td><a href="https://www.twilio.com/docs/api/errors/'.$errCode.'">'.$errCode.'</a></td>', $text); } } $event->return = $text; }); 5 Link to comment Share on other sites More sharing options...
bernhard Posted December 21, 2019 Share Posted December 21, 2019 21 hours ago, nabo said: This would work perfectly in a textfield but unfortunately I have these fields inside a Profields: Textareas and Profields: Table. Sorry, obviously I missed that info ? I don't know how complex your field output is, but you could nonetheless use my hook and recreate the complete output. Maybe that could even improve your UI.. Just to throw in an idea without knowing your scenario. Link to comment Share on other sites More sharing options...
adrian Posted January 4, 2020 Share Posted January 4, 2020 @nabo - I just did some cleanup of that code and was actually also needing to link URLs, so I just use this: $text = preg_replace('/(<td>)(http(.*?))(<\/td>)/', '$1<a href="$2">$2</a>$4', $text); which is obviously much cleaner than the preg_match_all approach - I think I must have been in a rush last time and not thinking properly ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now