Make WordPress Core

Opened 12 years ago

Last modified 6 years ago

#22938 assigned enhancement

Presentation of hierarchical taxonomy in Media modal should be checkboxes rather than comma-separated tag list

Reported by: yeswework's profile yeswework Owned by: wonderboymusic's profile wonderboymusic
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: needs-patch
Focuses: ui, javascript Cc:

Description

Since 3.5, using register_taxonomy_for_object_type on attachments, if the taxonomy used is hierarchical, whereas in the edit attachment UI you see the normal list of checkboxes, in the corresponding modal it is presented as a comma-separated list of slugs, as if it were a non-hierarchical taxonomy (tags rather than categories). I'm sure this is not a bug / mistake / oversight, but at best it's a little unintuitive (you need to have memorised the category slugs to add new ones) and worst a bit dangerous (risk of adding unwanted categories), and it would be great if in future it was presented here too as a list of checkboxes.

Attachments (3)

Screen Shot 2012-12-14 at 15.01.02.png (7.4 KB) - added by yeswework 12 years ago.
shows a hierarchical taxonomy presented like a tag list in 3.5 media modal
22938.patch (2.9 KB) - added by jessepollak 10 years ago.
Screenshot 2014-10-26 20.04.22.png (515.2 KB) - added by jessepollak 10 years ago.
Screenshot of checkbox attachment taxonomy chooser

Download all attachments as: .zip

Change History (33)

@yeswework
12 years ago

shows a hierarchical taxonomy presented like a tag list in 3.5 media modal

#1 @knutsp
12 years ago

  • Cc knut@… added

#2 @SergeyBiryukov
12 years ago

  • Component changed from General to Administration

#3 @helen
12 years ago

  • Component changed from Administration to Media
  • Keywords ui-focus added

#4 @mendelk
12 years ago

  • Cc menkra@… added

#5 @ericlewis
10 years ago

  • Keywords needs-patch added
  • Version set to 3.5

#6 @leemon
10 years ago

Now the new 4.0 media library edit attachment modal shows categories as a comma-separated list of slugs, too. Why? This is a backward step.

#7 @DrewAPicture
10 years ago

  • Milestone changed from Awaiting Review to 4.1

I'd like to come up with a solution for this in 4.1. Definitely seems pretty weird to relegate hierarchical taxonomies to non-hierarchical-type input boxes.

#8 @wonderboymusic
10 years ago

  • Focuses javascript added
  • Owner set to wonderboymusic
  • Status changed from new to assigned

I will fall on this sword

#9 @ericlewis
10 years ago

Select2 y'all

This ticket was mentioned in IRC in #wordpress-dev by DrewAPicture. View the logs.


10 years ago

This ticket was mentioned in Slack in #core by jessepollak. View the logs.


10 years ago

#12 @jessepollak
10 years ago

I have a patch for this incoming — I'll get it up later this evening. It's not perfect, so I'm hoping to get some feedback advice, then clean it up.

#13 follow-ups: @jessepollak
10 years ago

  • Keywords has-patch dev-feedback needs-testing added; needs-patch removed

I'm attaching a patch & screenshot of an MVP of the fix for this. Right now, it displays the categories for a media item as a list of checkboxes and saves them. I have a few questions and TODOs:

  1. I use wp_terms_checklist() which in turn relies on Walker_Category_Checklist which is relatively inflexible. Primarily, it can only output inputs of the form name=post_category[] or tax_input[$taxonomy]. That's a different form than what's used to saved AttachmentCompat's in Backbone, so I have to str_replace to get it in the correct form. I know this is horrible, but I'm not sure what the best way to proceed is — should I rewrite Walker_Category_Checklist, so it can be more modular?
  1. wp_terms_checklist() outputs to the buffer, so I use ob_start() etc to get the content which is passed via AJAX. Is this acceptable or — again — should I refactor to make it possible to get it as a string rather than output?
  1. In the media.view.AttachmentCompat class, I add an if statement in the save method that handles the case where the input is a series of checkboxes (before this, they were always a single input of type=text or type=hidden). Is this acceptable or should I subclass media.view.AttachmentCompat specifically for ones that are taxonomies of some sort.
  1. I've only been testing this in the Attachment Edit & Create pages and with the category taxonomy. Can anyone think of other objects and/or taxonomies I should be testing on?
  1. I have done zero styling of the check box. Right now, on my checklist is: restrict height of container and add overflow: scroll, indent child categories, align checkbox and text, add visual border to contain checkboxes. Any other thoughts?

Appreciate any and all feedback :)

Last edited 10 years ago by jessepollak (previous) (diff)

@jessepollak
10 years ago

@jessepollak
10 years ago

Screenshot of checkbox attachment taxonomy chooser

This ticket was mentioned in Slack in #core by jessepollak. View the logs.


10 years ago

#15 @johnbillion
10 years ago

  • Milestone changed from 4.1 to Future Release

#16 in reply to: ↑ 13 @husobj
10 years ago

Replying to jessepollak:

  1. I use wp_terms_checklist() which in turn relies on Walker_Category_Checklist which is relatively inflexible. Primarily, it can only output inputs of the form name=post_category[] or tax_input[$taxonomy].

This may relate to issue #28053 - The saving of media modal fields doesn't cater for multiple form fields of the same name named with empty square brackets such as post_category[]. You would expect these to get submitted and handled as an array but only the last field gets submitted.

Would handling that issue perhaps help here?

#17 in reply to: ↑ 13 @boonebgorges
9 years ago

  • Keywords needs-patch added; has-patch dev-feedback needs-testing removed

Thanks for the initial patch, jessepollak. Some thoughts:

  1. I use wp_terms_checklist() which in turn relies on Walker_Category_Checklist which is relatively inflexible. Primarily, it can only output inputs of the form name=post_category[] or tax_input[$taxonomy]. That's a different form than what's used to saved AttachmentCompat's in Backbone, so I have to str_replace to get it in the correct form. I know this is horrible, but I'm not sure what the best way to proceed is — should I rewrite Walker_Category_Checklist, so it can be more modular?

Yeah, definitely feel free to refactor, but it might be awkward in this case, since it looks like you need the $name to contain a reference to the attachment ID. You could make this work with the creative use of a filter, or perhaps by breaking the $name logic into a separate method of Walker_Category_Checklist and then subclassing it so as to override.

  1. wp_terms_checklist() outputs to the buffer, so I use ob_start() etc to get the content which is passed via AJAX. Is this acceptable or — again — should I refactor to make it possible to get it as a string rather than output?

Definitely yes. An 'echo' param would be good.

  1. In the media.view.AttachmentCompat class, I add an if statement in the save method that handles the case where the input is a series of checkboxes (before this, they were always a single input of type=text or type=hidden). Is this acceptable or should I subclass media.view.AttachmentCompat specifically for ones that are taxonomies of some sort.

What you've done in the patch seems OK to me. If this is the only change necessary, let's not overengineer.

  1. I've only been testing this in the Attachment Edit & Create pages and with the category taxonomy. Can anyone think of other objects and/or taxonomies I should be testing on?

I don't think you need to handle other objects with this ticket. For taxonomies, you should handle any taxonomy where 'hierarchical' => true.

This ticket was mentioned in Slack in #core-images by joemcgill. View the logs.


8 years ago

This ticket was mentioned in Slack in #core by joemcgill. View the logs.


8 years ago

#21 @paaljoachim
8 years ago

I think it should look more similar to selecting or creating a category in a post.
Btw here is a screenshot from: https://wordpress.org/plugins/media-taxonomies/
(I have made a google doc comparing various media management plugins: https://docs.google.com/document/d/1Xgt8Cjv8rNcPwEwpECp3FgCOA5v1ehSkaA0uEFdQX6c/edit )

https://cldup.com/OE0psBeWki.jpg

Btw
There are plans on more research and on looking into adding taxonomies into the media library. If you want to get involved check out the core-images posts on make.wordpress.org/core/

Last edited 8 years ago by paaljoachim (previous) (diff)

This ticket was mentioned in Slack in #core-images by joemcgill. View the logs.


8 years ago

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


8 years ago

#24 @jlambe
8 years ago

Besides the UI choices (select2, metabox like in edit screen, ...) one thing that might enhances the current text input for attachment category would be a UI notice that shows to the user that the terms were saved.

It's not evident to the user that category terms are saved until the text input "refresh" with terms listed by alphabetical order ASC.

Also, I was thinking about enhancing the current text input with an "autosearch" feature. Just like the one implemented in the content editor when defining an anchor link. Perhaps re-use the existing work for the editor and provide similar autosearch for existing terms and if it doesn't add them to the input and finally return a UI (UX?) element that tells the user the terms were saved.

What do you think?

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


7 years ago

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.


7 years ago

#27 @swissspidy
7 years ago

#43093 was marked as a duplicate.

This ticket was mentioned in Slack in #core-media by paaljoachim. View the logs.


7 years ago

#29 @paaljoachim
7 years ago

Here is a link to WP Media Folder - Media Manager with Folders:
https://www.joomunited.com/wordpress-products/wp-media-folder

To show what a possible folder structure could look like.

This ticket was mentioned in Slack in #core by jayoswald. View the logs.


6 years ago

Note: See TracTickets for help on using tickets.