Download & Extend

When URL Display Cutoff parameter left blank it causes a warning

Project:Link
Version:6.x-2.10
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community

Issue Summary

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

#1

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

AttachmentSize
link.inc-url_cutoff-problem-feb-12-2013.patch 906 bytes

#2

It worked for me (so far).

Thanks for the quick reply.

#3

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

AttachmentSize
link.inc-url_cutoff-problem-feb-12-2013_2.patch 980 bytes

#4

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.

#5

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?

#6

Status:active» needs review

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

#7

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

#8

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.

#9

+1 on the RTBC.

#10

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

AttachmentSize
link.inc_.patch 989 bytes

#11

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

#12

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

#13

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

#14

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