Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Afterpath Event Question #282

Open
rob-vd2 opened this issue Jul 4, 2020 · 3 comments
Open

Afterpath Event Question #282

rob-vd2 opened this issue Jul 4, 2020 · 3 comments

Comments

@rob-vd2
Copy link

rob-vd2 commented Jul 4, 2020

I'm using the Cake4 branch to upload multiple images. I am using the afterPath event listener to customise the upload path so that my uploads are stored at:

articles\2020-07-04-104002\file_1.jpg

In order that the path does't include the folder "files" (my upload field as per the config) I had to do the following: - is this the best approach?

$path->setField(null);

Further, Is it possible to use the slug of the article in place of the data stamp, for example:

articles\my-article-title\file_1.jpg

I have looked into the createPath function of ProfferBehaviour but can't see how I can pass the parent entity (Articles) into the event where I'd need it to construct the path.

If this requires some custom development I would be happy to get involved and create a PR but I don't want to re-invent the wheel.

Thanks!

@davidyell
Copy link
Owner

To change the folder your uploads are stored in, change the root config https://github.com/davidyell/CakePHP-Proffer/blob/cake-4/docs/configuration.md#configuring-the-behaviour-in-your-table

Well the path class constructor takes an entity, so you could pass some data into the path clas instance that way if you wanted to interpolate something into the path.

@rob-vd2
Copy link
Author

rob-vd2 commented Jul 19, 2020

Thanks - when you mention the path class are you referring to: ProfferPath.php. If so when I debug the $entity in the constructor the entity in this case is the image itself - since the Proffer behaviour is attached to a hasMany relationship - ArticleImages. Since articles hasMany ArticleImages I need access to the Article entity here (for the article name).

@davidyell
Copy link
Owner

You may need a custom path class which can lookup the association. Or perhaps contain the association so it's present in the entity?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants