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.
Now we have entities, I seem to be replicating the author form element from node module a lot.
It would be handy to have it as a ready-rolled form element.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1620954.elements.author-field.patch | 1.76 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedHere's a patch that seems to work :)
A nice bonus feature would be an option to set the value to the global $user if the value is empty, but I'm not sure how best to do that.
Comment #2
joachim CreditAttribution: joachim commented> A nice bonus feature would be an option to set the value to the global $user if the value is empty,
I've been thinking more about this, and I see two options:
A. Set '#default_value' to the magic value of 'user' to mean 'put in the current user's UI'.
Pro: it's a one-liner to code:
Con: it's a magic value, and those are bad.
B. Add a key '#use_global_user_if_empty'.
Pro: it's explicit.
Con: it's two lines of code, so it's not actually a saving over having to do a 'global $user;' yourself. And the key name is a bit wordy.
I'm leaning towards B or neither.