Media entity storage path change on save dynamically

Created on 19 November 2015, about 9 years ago
Updated 6 June 2023, over 1 year ago

I have created a media entity type named "audio" (using media_entity module) which have a entity reference field and an file field. Now I want to rename and move files attached to that entity in a directory which is created according to the title of referenced entity's content.

For example I have an media entity type "audio" which has a file field which accepts mp3 and an entity reference field which is referenced to a node type "test". I have created two "test" type content "hello_test" "hello_test_2". Now if I create a content of media entity type "audio" named "test audio" with referenced entity "hello_test" and a mp3 file named "abc.mp3" then while saving "test audio" the mp3 file should be renamed as "hello_test.mp3" and it should be stored into "hello_test/" directory.

I tried it using hook_entity_presave and hook_ENTITY_TYPE_presave but it did not work. Is there any way to rename and move file in this way before saving the entity.

and also please suggest if it is possible using drupal 8 rules.

💬 Support request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇮🇳India rubela_shome

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024