Problem/Motivation
This idea came up while working on #2831274: Bring Media entity module to core as Media module. Media entity comes with images that are used as fallback thumbnails. Since they are stored in an image field when they are used they need to live in a public:/ or private:/ files directory.
Media solves that by copying them into the public directory on install. Solution is not the nicest though.
Proposed resolution
It would be nice if core would provide some kind of mechanism for modules to declare the list of files they ship with and need to be publicly accessible. It could be another yml file for example.
Core would then handle this automatically; make sure files are copied to a place inside webroot when module is installed and removed from it when they are uninstalled.
If we would do that we could start moving the actual modules out of the webroot, which would be great for the security. And media would be happy since it woudn't need to use the custom not-so-nice logic that it currently has :).
Alternative
Leverage #2927968: Add system stream wrappers to core
Remaining tasks
TBD
Comments
Comment #2
phenaproximaThis would certainly benefit Lightning. Pretty much since day one, one of our install routines has had to copy a PNG file from a module into the public files directory so that Embed can use it as the icon for a CKEditor button. Having the file automatically copied by a standard API would save us some trouble.
The relevant code in Lightning: http://cgit.drupalcode.org/lightning/tree/modules/lightning_features/lig...
One possible approach I suggested in IRC, that would not involve copying icons around, would be to implement a new stream wrapper whose only purpose is to link to icons -- either default ones provided by extensions, or overridden ones in a site-owned files directory.
For example, take a URI like this:
icon://node/image.pngThis would first try to usepublic://icons/node/image.png, if it exists; otherwise, it would fall back tocore/modules/node/icons/image.png. One URI that canonically refers to a particular icon, which may exist in several places. I'm not sure how feasible this would be, or even if it's a good idea, but it's perhaps a little more slick than bodily copying icons into the public files directory.Comment #3
sahilsharma011 commentedComment #5
geek-merlinIsn't this problem neatly solved when we have module:// stream wrappers?
Implementing this is as trivial as copying a contrib to core:
#2927968: Add system stream wrappers to core
(For some special use case where modules are not publicly readable, *that* should be the wanted API that does the copying magick.)
Comment #9
seanbLet's postpone this on #1308152: Add stream wrappers to access .json files in extensions.
Comment #18
nicxvan commentedComment #19
catchModules can reference their own files relatively, as they already do in libraries.info.yml no need for a stream wrapper for this.
Comment #20
nicxvan commentedComment #21
nicxvan commentedComment #22
nicxvan commentedI've compared these two issues and even though this one is slightly older the other is more active with more detail.
I have transferred the relevant info there thanks everyone!