Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The pathauto function doesn't return the filename field for php versions older than 5.2. This breaks the filefield-onlyname token replacement.
I have attached the patch I am using for this.
Comment | File | Size | Author |
---|---|---|---|
#11 | filefield-848528-3.patch | 730 bytes | alexpott |
#9 | filefield-848528-2.patch | 787 bytes | alexpott |
#8 | filefield-848528.patch | 921 bytes | alexpott |
#7 | filefield.token_.inc_.patch | 175 bytes | mrhanlon |
filefield.token_.inc_.patch | 281 bytes | mrhanlon |
Comments
Comment #1
quicksketchSounds like this may be a problem in pathauto or the token replacement functions. Rather than adding a work-around to FileField's token handling, we should just make sure that the correct tokens get passed in to begin with.
Comment #2
mrhanlon CreditAttribution: mrhanlon commentedI don't think so. In the php docs (http://php.net/manual/en/function.pathinfo.php) it says the return value for pathinfo is:
In the changelog:
In the source for filefield.token.inc, line 60:
For PHP version older than 5.2, the $info['filename'] will not be set, as per PHP docs. Hence, the patch. I found that this is the similar approach that has been used in other modules due to this problem. E.g. such as filefield paths (see #515044: Add support for the [filefield-onlyname-original] token in PHP 5.1 (and lower)), although I am not using that module myself.
Comment #3
mrhanlon CreditAttribution: mrhanlon commentedWhoops. It appears that in my original posting, I mistakenly said "pathauto" rather than "pathinfo" thus the confusion. The problem lies within the php built-in function pathinfo, not the pathauto module.
Comment #4
quicksketchAh, okay that makes much more sense. pathinfo() definitely did change and I've seen this problem elsewhere. Rather than putting an IF statement in there though, let's just use basename($info['filepath']) instead when we set filename and do the same thing for all versions of PHP.
Comment #5
mrhanlon CreditAttribution: mrhanlon commentedSure, a solution independent of PHP version would be great. But with basename, you'd get the filename+extension, not just the filename, which is what the onlyname token was. So wouldn't you still have to do a substr to extract filename, or am I missing something?
Comment #6
quicksketchAh, yes you have to use basename($info['filepath'], '.' . $info['extension']).
Comment #7
mrhanlon CreditAttribution: mrhanlon commentedCool. For completeness I have attached a new patch.
Comment #8
alexpottHere's a patch that produces the same filefield-onlyname token regardless of php version - and also fixes a PHP Notice: Undefined Variable issue using php 5.1.6 and the current version of filefield.
The code change is:
to
Comment #9
alexpottDoh! Now reading the issue queue fully (when will I learn?) seems like quicksketch wants to do the same regardless of php version... patch attached to do just that.
Comment #10
quicksketchA faster way (or at least shorter) is:
Comment #11
alexpottWell here's a new patch based on quicksketch's more elegant line of code that bears a remarkable resemblance to #7 :) - I've tested this on php 5.1.6 and it works great.
Comment #12
quicksketchFinally committed. Thanks alexpott.