We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34078
    • 76 Posts
    Is there a way (without core hacking) to custom automatics alias in MODx Revolution 2.1.0-RC3 ? If, instead the alias generated from the pagetitle, I want an alias generated from id and pagetitle, how to do that ?

    In fact, I need to have resources with the same pagetitle under the same parent. For example : /parent/1-child.html and /parent/2-child.html

    I try to create a OnBeforeDocFormSave plugin, but MODx check the alias before that.

    I know the package translit allows custom transliteration but there is no reference to the resource created or updated. Even if translit had a reference to resource object, the new resource would have no ID.

    Somebody has an idea ? Is there another solution ?
      • 34078
      • 76 Posts
      A dirty solution is to remplace, in the getAliasPath from /core/model/modx/modresource.class.php :
      $fullAlias= $aliasPath . $fullAlias . $extension;

      by
      $fullAlias= $aliasPath . $fullAlias . '-' . uniqid() . $extension;


      So the resource URI looks like : /parent/child-4dbbdd405093e.html

      Is there a better way to do that ?
        • 34078
        • 76 Posts
        Finaly, I made an OnDocFormSave plugin, it’s not perfect but works.

        <?php
        $eventName = $modx->event->name;
        switch($eventName) {
          case 'OnDocFormSave':
            if(!isset($_REQUEST['alias']) || empty($_REQUEST['alias']))
            {
              $alias = $resource->get('alias').'-'.$resource->get('id');
              $resource->set('alias', $alias);
              $resource->save();
            }
          break;
        }


        Thanks to lossendae for his help.