Problem/Motivation
Users might require the dynamic creation of taxonomy terms during the Media editting process.
However the default field settings do not have the "Create referenced entities if they don't already exist" (auto_create) option available to configure.
Steps to reproduce
Attempt to create/edit a Media entity, but also attempt to put in a new Directory Taxonomy term.
Proposed resolution
Add a "Create referenced taxonomy term if they don't already exist" option in the Media Directory configuration page which updates the existing media_directories_entity_base_field_info() hook.
Something along the lines of:
$fields['directory']
->setSetting('handler_settings', [
'target_bundles' => [$vocabulary => $vocabulary],
'auto_create' => true,
'auto_create_bundle' => $vocabulary,
]);
Remaining tasks
Provide patch/issue fork.
User interface changes
There will be a new form configuration to enable/disable the ability to create new taxonomy terms as necessary.
API changes
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3340280-media_directories-auto-create-taxonomy-terms-4.diff | 4.04 KB | codebymikey |
Issue fork media_directories-3340280
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ytsurkThank you for the input.
This definitely would be a nice feature IMO. And maybe even easily implementable. I'll have a look into this when I find some time ...
Comment #4
codebymikey commentedAttached an initial draft of this implementation. Please feel free to review, and update as necessary.
Also added a todo regarding using config events to trigger the cache clear side effects.
Making changes to the configuration via other means e.g. programmatic approach or via Drush should also trigger the invalidation of the specific caches. In this case, probably something like this:
Comment #5
codebymikey commentedOne slight UX limitation at the moment is that if the user does add a new taxonomy term dynamically from the media_directory_ui browser, it doesn't refresh the list of folders, but for my current MVP, this implementation is suitable for now.
Comment #6
tinytina commented+1 for this feature.
Tried diff from #4 with media_directories 2.1.0-beta2 and core 10.0.9, seems to work pretty well.