0

I am using ECK (Entity Construction Kit) to create my custom entities. Now I want to create custom url for various operation on my entities such as create (example.com/my-entity/create) or view (example.com/my-entity/view/custom-unique-field)

I have tried pathauto but it seems I cant define custom patterns for my own entities. Any help towards this step is highly appreciated.

Thanks, Naveen

4

You can use the path (url alias) module for the create path. Since that's a single url, you can create a single path alias to change that.

It's a bit harder for your custom entities. You would have to create a custom module and integrate with path auto module to be able to create path aliases for the view urls of your custom entities. It's a lot of code, you can see how the path auto module does it for the node module. But be warned, it's not easy as there are many parts.

The gist of it is that you need to make some tokens available for the path system you are going to make, like the entity label and such. Then you need to create a function that can create an alias when given an entity. This is, however, a bit harder since you need to use the path auto API functions for this.

  • 2
    URL alias makes sense for creating an entity, which would be single but for viewing and might be editing, it wont be possible :( Did you have a chance to look into drupal.org/sandbox/damz/1332096. The module promises to solve this particular problem, though still in sandbox and will need to use it. – Naveen Mar 19 '12 at 2:54
  • @Naveen I have solved this problem before in several cases of custom url patterns that needed to be rewritten: (Views, panels, and custom entity urls), so trust me when I say the above method will work. But it's not easy for novice Drupal developers. – googletorp Mar 19 '12 at 12:24
  • thanks @googletorp. Any tutorial / code sample for reference. It would be really helpful. – Naveen Mar 20 '12 at 6:04
  • @Naveen The closest thing I've come has been to look at how path auto did it for the node module. You basically need to do the same thing, only for your custom entity. I could show my own code, but that wouldn't be any better than what path auto does with nodes it would be better to use for you than any of my code, since you know how nodes work already. – googletorp Mar 20 '12 at 14:13

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.