-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable labels for fields #1659
Comments
Like a lot of problems in Drupal life, Context might be useful here. This StackExchange post shows how to programmatically change a field's display label. If this works the way it says it does, it could form the basis of a Context Reaction to change a field's label. Edit: this hook doesn't cut it. See my next comment for a tested solution. |
Context is what was mentioned in a discussion of this yesterday. I think one important piece of this is that it's the kind of thing a Metadata Librarian expects to be able to set up or specify without having to request developer resources at their institution for every particular field that needs to be handled. So we were talking about whether there could be generalizable approach to creating context-based field profiles, via the UI, for collections or field_model values. Defining the context could mean being shown a list of all the defined fields with their default display labels, with the ability to type a context-specific display label into a text box, and possibly also check/uncheck radio button/box for "Display in form" and "Display for admin", "Display for public", etc (role-based display) |
@kspurgin after a bit of playing around I was able to find a way to change field labels in the display of a node. For example, the default label on the "Extent" field looks like this: but I've demonstrated to myself that the label can be programmatically altered: I'm pasting in the code that alters the label for the benefit of a developer who might want to take this to the next level: /**
* Implements hook_entity_display_build_alter().
*/
function markstestmodule_entity_display_build_alter(&$build, $context) {
$build['field_extent']['#title'] = 'How much?';
} If this is implemented as a Context Reaction, the UI you describe for assigning field -> label pairs would be possible, but the options would be limited to "being shown a list of all the defined fields with their default display labels, with the ability to type a context-specific display label into a text box" and then defining the desired label. The '"Display in form" and "Display for admin", "Display for public", etc (role-based display)' options would be defined in the Context Conditions (a Context needs both a Condition and a Reaction). The code that I've pasted above doesn't apply to forms (only display) but I'd be surprised if there wasn't a way to alter the fields in the form as well. This wouldn't need to be implemented as a Context, but doing so provides a lot of flexibility. If it was implemented not as a Context Reaction, the UI could be much as you describe, but the options that define when a particular custom label is displayed would be limited to whatever options are built into that UI. We will likely want this ability in our Islandora 8 sites since we provide collection-specific labels for metadata fields in our current Islandora 7 repo. I would love to take this on but I'm already over extended. Maybe someone else can find the time to build this out fully. |
in the tech call, hertzel found https://www.drupal.org/project/entity_form_field_label which may be applicable here |
I have tried to install this module to test it but composer runs out of memory, even when I boost my VM's PHP memory up to 500MB. FWIW, it appears that it uses |
I'd like to add a use case that has come up in planning migrating our IR to Islandora. Like many IRs, the majority of items in it are theses. Our Faculty of Grad Studies is requesting that prior to a specific date, the thesis senior advisor be identified as "Supervisor", and after that date, "Senior Supervisor". Being able to automatically define the label based on the published date would be an optimal approach. Otherwise, we'd need to either use two separate fields, or (if we use a typed relation field), two subtlely-different-due-to-current-university-policy relator type. I recognize that if in this case the label was changed by a Context Reaction, the Context Condition would need to account for a less-than/greater-than check in a particular field. If it's changed by some other mechanism, we'd still need to be able to test the value in the Date Issued field in some configurable way. Tagging my colleague @librarychik on this since she's PM for the migration. |
Related:
|
From Paige M,
"split field display labels by collection in Islandora 8? We currently have one "abstract" field, but want the display to be "Abstract" in one collection and "Description" in another."
Right now this means either:
:sad face:
Edit to add Use Case verbiage - RL
The text was updated successfully, but these errors were encountered: