Skip to content
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

Open
rosiel opened this issue Oct 26, 2020 · 7 comments
Open

Configurable labels for fields #1659

rosiel opened this issue Oct 26, 2020 · 7 comments
Labels
Subject: Metadata related to metadata issues. Consider also using the search tag. Type: documentation provides documentation or asks for documentation. Type: use case proposes a new feature or function for the software using user-first language.

Comments

@rosiel
Copy link
Member

rosiel commented Oct 26, 2020

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:

  • using two different fields
  • using two different content types.

:sad face:

Edit to add Use Case verbiage - RL

Title (Goal) Configurable labels for fields
Primary Actor Collection Manager, Site Administrator
Scope Metadata display
Story As an site/collection administrator, I wish to be able to update field labels that display to users in a contextual way (based on type or collection) including for fields that are linked agent fields
@mjordan
Copy link
Contributor

mjordan commented Oct 27, 2020

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.

@kspurgin
Copy link
Contributor

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)

@mjordan
Copy link
Contributor

mjordan commented Oct 28, 2020

@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:

extent

but I've demonstrated to myself that the label can be programmatically altered:

howmuch

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.

@elizoller
Copy link
Member

in the tech call, hertzel found https://www.drupal.org/project/entity_form_field_label which may be applicable here

@mjordan
Copy link
Contributor

mjordan commented Oct 29, 2020

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 hook_field_widget_form_alter() to do within forms what hook_entity_display_build_alter() does in the above snippet.

@mjordan
Copy link
Contributor

mjordan commented Jan 12, 2021

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.

@kstapelfeldt kstapelfeldt added Type: documentation provides documentation or asks for documentation. Subject: Metadata related to metadata issues. Consider also using the search tag. and removed architecture labels Sep 25, 2021
@rosiel rosiel added the Type: use case proposes a new feature or function for the software using user-first language. label Oct 22, 2021
@rosiel
Copy link
Member Author

rosiel commented Oct 22, 2021

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Subject: Metadata related to metadata issues. Consider also using the search tag. Type: documentation provides documentation or asks for documentation. Type: use case proposes a new feature or function for the software using user-first language.
Projects
Development

No branches or pull requests

5 participants