0

I have a single PHP file which makes a bootstrap of Drupal 7. The code is below. When I try to use pathauto_clean_string in a spanish string with accents (á é ... , etc.) it deletes the character instead of removing the accent using transliteration module (also affects other special chars, obviously). I have included also this module in the bootstrap but cannot have the PHP script to behave exactly as the Drupal site, which is doing properly the transliteration in file names and also from my own custom module.

define('DRUPAL_ROOT','/home/example.com/public_html');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
require_once DRUPAL_ROOT . '/sites/all/modules/transliteration/transliteration.inc'; 
 require_once DRUPAL_ROOT . '/sites/all/modules/pathauto/pathauto.inc';

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

if(isset($_GET['string'])) echo pathauto_cleanstring(urldecode($_GET['string']));

Result with www.example.com?string=está-cañón : est-can

Result with the same string and module, same function and correct, expected, result: esta-canon

6
  • Your code works properly for me; can you replicate this issue in local development environment? – Aram Boyajyan Mar 21 '16 at 12:44
  • Working in XAMPP under Windows XP. Apparently same config. In remote (Linux) not working, in PHP file (code above), working under "full Drupal" environment (code inside module). Now is where I cannot understand a thing. – Cesar Mar 21 '16 at 13:01
  • Strange; it's probably something in PHP configuration. Did you try removing urldecode()? – Aram Boyajyan Mar 21 '16 at 13:19
  • Yes, I tried even "illogical" urlencode. Also injecting the string directly in a variable. I see that transliteration is not necessary after all, maybe pathauto loads it when is needed. I am using PHP 5.5x in server and changed it recently, but it is strange that it does not affect the module. I will try to debug it to low level stage to see what are the input - output of the function and where is the change. – Cesar Mar 21 '16 at 13:28
  • Here's just an idea: what about the encoding of your PHP script? Try resaving it to UTF-8, I've see all sorts of weird things when this is not the case for whatever reason. – Aram Boyajyan Mar 21 '16 at 13:40
0

After having a look at the code from the pathauto_cleanstring function, I would suggest testing the following:

  1. Checking the value of pathauto_transliterate prior to calling the pathauto_cleanstring function

    variable_get('pathauto_transliterate', FALSE)

  2. If that value is FALSE, you probably found the reason. Try setting that variable to TRUE to force use of transliteration inside the pathauto_cleanstring function. N.B.: You only need to set this value once.

    variable_set('pathauto_transliterate', TRUE), or
    drush vset pathauto_transliterate TRUE

  3. Try your code again. Fingers crossed!

I suspect that your code never actually uses the transliterate function, but that is something that you can check by dumping the 'pathauto_transliterate' variable in the various scenarios where your code is executed (in-module, custom script, etc.)

3
  • It throws a 500 internal server error. In any case, in the module the working is right, and I would not set a variable that is not multi-user, because it is completely global to the site, so don't think it is a good recommendation to change the value of something that should not change - it is set in the admin frontend. – Cesar Mar 22 '16 at 11:31
  • The first thing you need to check, without changing the value of the variable, is if you get the same value for that variable, inside and outside of the module setting. If you don't that can explain the mystery you are facing. What is the value of that variable at the moment? – Stefanos Petrakis Mar 22 '16 at 12:40
  • After clearing out some things, the variable when I make the get method call is 1, true. The reason of the behaviour is other. Maybe it will be an enduring mystery for the next generations. – Cesar Mar 22 '16 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.