I have a Content Type that contains a field that is a web link. After upgrading from 6.x-2.9 to 6.x-2.10, when I display nodes of that Content Type I get the following warning:
warning: substr() expects parameter 3 to be long, string given in /var/www/drupal/sites/all/modules/link/link.inc on line 111.
The URL Display Cutoff: parameter for the web link field is blank. The help says "If the user does not include a title for this link, the URL will be used as the title. When should the link title be trimmed and finished with an elipsis (…)? Leave blank for no limit." so I should be able to leave the parameter blank. If I put a value in for the URL Display Cutoff: parameter the warnings go away.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | link.inc_.patch | 989 bytes | dnmurray |
| #3 | link.inc-url_cutoff-problem-feb-12-2013_2.patch | 980 bytes | rbruce |
| #1 | link.inc-url_cutoff-problem-feb-12-2013.patch | 906 bytes | devvmh |
Comments
Comment #1
devvmh commentedThis same issue spat out the error messages but also was messing up the display of a "Link" content type yesterday. The attached patch solves the issue (I hope!!). It's worked so far :)
Comment #2
rbruce commentedIt worked for me (so far).
Thanks for the quick reply.
Comment #3
rbruce commenteddevv, after further testing the patch you submitted did not work for me.
I came up with the attached patch and it seems to have fixed my problem and I think the logic should hold for other cases.
(p.s., this is my first patch for a Dupal module so if I did not follow protocol, plz let me know)
Thanks
Comment #4
devvmh commentedHmm. I'm not sure I understand your patch. What was your error message? Mine was telling me that $field['display']['url_cutoff'] was a string when it should be a number. Suddenly I can't even replicate the error though haha.
Comment #5
rbruce commentedThe way the url_cutoff is supposed to work is that if it is left blank then there is no cutoff (i.e., the entire url is displayed).
In your patch, if url_cutoff is a string, you are setting url_cutoff to 0 which effectively replaces the entire url with elipses. When I left the field blank it was being treated as a string (???) so the url was being cutoff at 0.
The logic should be: if url_cutoff is blank, do nothing; if it has a value, cut off the url after that many characters. I added one extra check to the if statement on line 110:
(
if (is_array($field['display']) && isset($field['display']['url_cutoff']) &&(strlen($field['display']['url_cutoff'] <> 0))&& strlen($display_url) > $field['display']['url_cutoff']) {)so if the field is blank (i.e., string length is = 0) then it will just use the display_url, otherwise it will cutoff the url.
I tested this both with the url_cutoff blank and with a value and it worked the way I expected it to in both cases.
Does this make sense?
Comment #6
squarecandy commentedI also experienced this issue on updating to 6.x-2.10.
#3 worked like a charm.
Comment #7
pokermoneyclips commentedPatch in #3 took away the php error for me as well on 6.x-2.10. Thanks a ton rbruce.
Comment #8
mathieu commentedPatch in #3 fixed the issue for me, on a site not using any cutoff. Thanks. 3rd review, setting RTBC.
Comment #9
benclark commented+1 on the RTBC.
Comment #10
dnmurray commentedI do things backward. I fixed it, then came here to look for it. !empty() is a little less verbose than the patch and works fine:
if (is_array($field['display']) && !empty($field['display']['url_cutoff']) && strlen($display_url) > $field['display']['url_cutoff']) {
$display_url = substr($display_url, 0, (int) $field['display']['url_cutoff']) ."...";
}
Comment #11
axle_foley00 commentedThe Patch in #3 worked for me also. Would be nice if this could now be rolled into an official release for the module.
Comment #12
hwasem commentedThank you, rbruce for the patch in #3. That fixed my links that were showing as just "...".
Comment #13
Rob_Feature commentedYup, tested and fixed my issue. Please commit this.
Comment #14
Anonymous (not verified) commentedUsed 3rd patch to fix. link.inc_.patch
Comment #15
kaare#10 seems to be the cleanest way to fix this. rtbc.
Comment #16
jcfiala commentedOkay, fixed using the patch from #10, which I agree is a bit cleaner with using empty(). But thanks for everyone's input on this.
I suspect the dev version marked Dec 16th will contain this fix, as it's almost 1am Mountain time when I'm typing this. But please if you're still interested in this item take a moment to test when it makes it's way into dev release.