Guest User

Untitled

a guest
Jun 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. // if we are in context www-en…
  3. if ($modx->context->get('key') == "www-en") {
  4. $o = '';
  5. // …grab www-fr infos
  6. $modx->switchContext('www-fr');
  7. $ss = $modx->getOption('site_start');
  8. $ctx = $modx->context->get('key');
  9. // grab datas from TV named multi (containing ID of the translated resource)
  10. $tvv = $modx->resource->getTVValue('multi');
  11. // if there is no translation (empty TV), return the start_start ID
  12. if (empty($tvv)) {
  13. $o = $ss;
  14. } else {
  15. $o = $tvv;
  16. }
  17.  
  18. $u = $modx->makeUrl($o,$ctx,'','full');
  19. // going back to original context
  20. $modx->switchContext('www-en');
  21. return $u;
  22. }
  23. // else if we are in context www-fr…
  24. else if ($modx->context->get('key') == "www-fr") {
  25. // …grab www-en infos
  26. $modx->switchContext('www-en');
  27. $ss = $modx->getOption('site_start');
  28. $ctx = $modx->context->get('key');
  29. $tvv = $modx->resource->getTVValue('multi');
  30.  
  31. if (empty($tvv)) {
  32. $o = $ss;
  33. } else {
  34. $o = $tvv;
  35. }
  36.  
  37. $u = $modx->makeUrl($o,$ctx,'','full');
  38. // going back to original context
  39. $modx->switchContext('www-fr');
  40. return $u;
  41. }
  42. // we are somewhere else…
  43. else {
  44. // …return an error (enhance later for > 2 lang)
  45. return '#error';
  46. }​
Add Comment
Please, Sign In to add comment