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.

Comments

devvmh’s picture

StatusFileSize
new906 bytes

This 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 :)

rbruce’s picture

It worked for me (so far).

Thanks for the quick reply.

rbruce’s picture

devv, 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

devvmh’s picture

Hmm. 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.

rbruce’s picture

The 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?

squarecandy’s picture

Status: Active » Needs review

I also experienced this issue on updating to 6.x-2.10.
#3 worked like a charm.

pokermoneyclips’s picture

Patch in #3 took away the php error for me as well on 6.x-2.10. Thanks a ton rbruce.

mathieu’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #3 fixed the issue for me, on a site not using any cutoff. Thanks. 3rd review, setting RTBC.

benclark’s picture

+1 on the RTBC.

dnmurray’s picture

StatusFileSize
new989 bytes

I 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']) ."...";
}

axle_foley00’s picture

The Patch in #3 worked for me also. Would be nice if this could now be rolled into an official release for the module.

hwasem’s picture

Thank you, rbruce for the patch in #3. That fixed my links that were showing as just "...".

Rob_Feature’s picture

Yup, tested and fixed my issue. Please commit this.

Anonymous’s picture

Used 3rd patch to fix. link.inc_.patch

kaare’s picture

#10 seems to be the cleanest way to fix this. rtbc.

jcfiala’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Okay, 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.