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.
Is it currently possible to hide the Path and Pathauto fields on e.g. a node form for certain content types while still allowing the alias to be created? I've tried doing a '#pre_render' callback and then change some of the $element['path'] values, but no matter what I do, if the fields end up being hidden then no alias is created, it just ends up as node/123. Any tips?
Comments
Comment #1
joekrukoskyI am running into this same issue. I have 'hidden' the node form path element for certain users in an after_build with:
$form['path']['#access'] = FALSE;
But for those users it disables the automatic alias generation. I have attempted to keep it enabled by also adding:
$form['#node']->path['pathauto'] = TRUE;
This doesn't work.
Anyone have any suggestions?
Comment #2
joekrukoskyHere's a solution I came up with. Not sure it's the best way, but it worked for my application.
Comment #3
adam-delaney CreditAttribution: adam-delaney commentedI believe by setting the #access to FALSE the pathauto default value is not getting set so a path is not being derived, however if you explicitly set the pathauto value to TRUE while setting the path access to FALSE you may hide the form items while still setting an automatic alias. This code worked for me.