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

Provide default name (and alt text for images) in add media form #1491

Closed
mjordan opened this issue Apr 22, 2020 · 9 comments
Closed

Provide default name (and alt text for images) in add media form #1491

mjordan opened this issue Apr 22, 2020 · 9 comments

Comments

@mjordan
Copy link
Contributor

mjordan commented Apr 22, 2020

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:

image_defaults

Non-image media:

document_defaults

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 😄).

@mjordan mjordan added the UX label Apr 22, 2020
@mjordan
Copy link
Contributor Author

mjordan commented Apr 22, 2020

We could prepopulate the Original name field while we're at it.

@mjordan
Copy link
Contributor Author

mjordan commented Apr 22, 2020

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.

@dannylamb
Copy link
Contributor

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

@mjordan
Copy link
Contributor Author

mjordan commented Apr 22, 2020

@dannylamb right, good catch. So we could limit this new "feature" to just Name and Alt text, since they depend on the parent node.

@mjordan mjordan changed the title Provide default name, alt text, and media use for add media form Provide default name (and alt text for images) in add media form Apr 22, 2020
@mjordan
Copy link
Contributor Author

mjordan commented Apr 24, 2020

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:

  1. In your Drupal's web/modules/contrib directory, clone this module (git clone https://github.com/mjordan/islandora_form_defaults.git)
  2. Enable it by running drush en -y islandora_form_defaults

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.

@manez
Copy link
Member

manez commented May 6, 2020

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.

@mjordan
Copy link
Contributor Author

mjordan commented May 6, 2020

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:

  1. What do people think of making "Original file" the default in Islandora's default configs, and

  2. @Islandora/8-x-committers Should the code I provide in https://github.com/mjordan/islandora_form_defaults.git that @manez just tested be merged into the Islandora module's code, or remain as a separate (but maybe cleaned up a little) module?

@manez
Copy link
Member

manez commented May 7, 2020

  1. I don't see a downside to setting a default option. It saves a click, but it doesn't lock anything in. I think it's a small thing to give a slightly better first impression for those trying out the "default" Islandora.
  2. I think this should go into default Islandora as well. It's a bigger deal than setting a default in a form, but it's still editable, so the end result is the same: saves a click if you like it; doesn't hinder you if you don't.

@mjordan
Copy link
Contributor Author

mjordan commented Apr 29, 2021

Closing this, PR was merged long ago.

@mjordan mjordan closed this as completed Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants