-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Drupal 8 vendor folder outside webroot #12499
Conversation
Can one of the admins verify this patch? |
(Standard links)
|
Assuming we can guaranty that composer always generates this autoload.php in the web root, then this change is fine - even better than my earlier PR :-) The thing is, while I can confirm that I see an autoload.php in all my Drupal projects, I don't see anything in the composer docs about it: https://getcomposer.org/doc/01-basic-usage.md#autoloading ... and I don't see that in my non-Drupal composer-based projects. So, it must be some Drupal thing that generates it? If we can pin down what that is, and know that it'll always be there, then this is fine. |
@dsnopek what about the cautious approach - try webroot first but fall back (possibly with some sort of notice) to vendor? |
add to whitelist |
As far as I know the autoload.php is always included in the Drupal 8 webroot. It isn't even generated by composer. |
@dsnopek @wannesderoy I think this link https://api.drupal.org/api/drupal/autoload.php/8.0.x might an indication that the file is in all branches |
test this please |
Hmm after reviewing @dsnopek and this PR, and also considering the fact that it's not always true to have autoload.php under webroot but in some cases it would be under webroot/vendor/ as per https://api.drupal.org/api/drupal/autoload.php/8.0.x I would suggest the following change: $autoloaderPath = array_filter([$root . '/autoload.php', $root . '/vendor/autoload.php'], function($path) {
if (file_exists($path)) {
return $path;
}
})[0];
$autoloader = require_once $autoloaderPath;
... |
|
After some detail investigation, I looked upon Drupal branches, checked the directory structure of return require __DIR__ . '/../vendor/autoload.php'; OR return require __DIR__ . '/vendor/autoload.php'; So I agree with @wannesderoy to rely on autload.php which includes the vendor/autoload.php inside or outside the webroot based on the different approach to create Drupal instance. @dsnopek are you ok with merging this PR? |
@monishdeb Exactly! The autoload.php in the root always has the correct path to the vendor folder. So to me it seems this is the best/simplest solution. No need for checks and fallbacks. |
Ok - I think this is merge-ready - ie. if we hear a confirmation from @dsnopek or no-one comments for a few days & tests pass it can be merged & the related PR can be closed |
I was hoping that we could first at least find the code that's generating that extra autoload.php. That would increase my confidence in it! |
Ok, so I dug into this a bit. It looks like the autoload.php in the release tarballs on Drupal.org was written by hand. It was added in this issue: https://www.drupal.org/node/2406681 When using Looking at the original D.o issue, it seems unlikely that this file will get removed - the idea was to encourage people to use it rather than vendor/autoload.php to allow moving the vendor directory. I suppose the technique for doing this could change in the Drupal 8 composer initiative, but I doubt that'll be removed in Drupal 8 to maintain BC (maybe in Drupal 9). In short: 👍 to this PR :-) |
Overview
Allow Drupal 8 vendor folder outside webroot
Before
Drupal dependencies in vendor folder could not be located outside webroot. Autoloading does not work.
After
Drupal dependencies in vendor folder can not be located outside webroot. Autoloading works.