-
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
Provide default name (and alt text for images) in add media form #1491
Comments
We could prepopulate the Original name field while we're at it. |
Start of a little custom module that does this for image media: <?php
/**
* @file
* Contains islandora_form_defaults.module.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_alter().
*/
function islandora_form_defaults_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form['#form_id'] == 'media_image_add_form') {
$params = \Drupal::request()->query->all();
$media_of_nid = $params['edit']['field_media_of']['widget'][0]['target_id'];
$node = \Drupal::entityTypeManager()->getStorage('node')->load($media_of_nid);
$title = $node->getTitle();
$form['name']['widget'][0]['value']['#default_value'] = $title;
}
} Might need to populate Alternative text field via JavaScript. |
You can set the default value of media use using field settings for each media type e.g. for file check out: http://localhost:8000/admin/structure/media/manage/file/fields/media.file.field_media_use |
@dannylamb right, good catch. So we could limit this new "feature" to just Name and Alt text, since they depend on the parent node. |
I've put together a tiny module that provides this functionality: for all media add forms, the prepopulated "Name" field is the title of the parent node. In addition, on the media add form for Image media, the "Alt text" field is prepopulated with the same thing. I am providing the module so people can test this functionality easily. I think the best place for this code is in within the main Islandora module. To test:
Now, when you add a media to a node, the Name field will be prepopulated. You can change the value of this field if you want. Same goes for "Alt text" in Image media. |
This is nice! Works just as advertised. I wonder if the description field would be more appropriate for the Alt text? Or is description too likely to be verbose? Setting "Original file" as default is one of the changes I usually make in my own testing demo VM. 👍 for making that standard in our default config. |
The description field is configured to be a lot longer (data type = long text) than the Alt text (data type = text, probably 255 characters max length). If we prepopulated the Alt text field with the value of the node's description field, we'd need to truncate it at the max lenght of the Alt text field. Two questions, if we want to move forward with this:
|
|
Closing this, PR was merged long ago. |
We could probably improve the UX when adding media by auto-populating the media Name to be the same as the parent node's title. For image media, the parent title could also be used as the pre-populated Alt text:
Non-image media:
Also, since most times users will be adding an Original File, that media use term could be selected by default.
This should be doable with some fairly simple form_alter code, although I haven't tried that yet. We could make this an option (toggle 😄).
The text was updated successfully, but these errors were encountered: