The core of Drupal 8 has a composer.json itself, which defines the necessary dependencies to it. However, the way that file core/includes/bootstrap.inc is defined causes the core becomes extremely attached to a predefined structure of the directories sites/modules/themes.
At line 134 of the file core/includes/bootstrap.inc has:
define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
Note that this does not give freedom to the developer to change the location of the directories sites/modules/themes. In this way only can use the core through the drupal/drupal package. Thus, it is not possible to have the drupal/core as dependence on any project other than the drupal/drupal, since it would be necessary to have the directories sites/modules/themes, as well as the front controllers, within the vendor directory of our application, which is unthinkable.
Simply change this line of code to:
if (!defined('DRUPAL_ROOT'))
define('DRUPAL_ROOT', dirname(dirname(__DIR__)));allow the developer to have control of the directory structure, and make drupal/core more decoupled and reusable.
Comments
Comment #2
lainosantos commentedComment #3
lainosantos commentedThere is many files that use the constant DRUPAL_ROOT. I think that it will require more refactor. :(
Comment #4
dawehnerUsing is not the problem right, its more about defining it ..., but yeah ideally DRUPAL_ROOT would be site by the front controller. Note: We also have
\Drupal\Core\DrupalKernel::getAppRootwhich is the same thing but rightComment #5
lainosantos commentedYou're right, dawehner.
I said about refactoring, because I realized that it not only uses the constant to refer the directories sites/themes/modules, but also use it to refer the core itself. As, for example, \Drupal\Core\Session\SessionHandler::write():
require_once DRUPAL_ROOT. '/core/includes/errors.inc';This confirms that there is a strong coupling between the drupal/core and drupal/drupal packages. Also among the directory structure, with no need.
Also have you talked about: \Drupal\Core\DrupalKernelInterface::getAppRoot().
Comment #6
lainosantos commentedComment #7
mile23+1.
We should work on decoupling everything. :-)
Comment #8
lainosantos commented+1
Comment #9
mile23Added this as a child issue, but never mentioned it here: #2631362: Inject DRUPAL_ROOT into DrupalKernel
Comment #20
joachim commentedNeeds an issue summary update if this is a meta.
And how does this relate to #2385395: Make Drupal core folder agnostic and allow it to be placed in vendor/drupal/core and #1672986: Option to have all php files outside of web root.?