Starting from
#2351919: Replace uses of drupal_get_path() with __DIR__ where possible β
, when the PHP code needs to include or parse files inside the module or theme directory space, will simply use _DIR_
instead of drupal_get_path()
. This is sufficient, intuitive and more performant than calling drupal_get_path()
.
However, drupal_get_path()
is widely used to refer files (.js, .css, images, assets) outside a module or theme. This isn't very intuitive for new developers. Stream wrappers make much more sense and simplify the API for developers trying to refer directories or files from outside the current extension in code.
Introduce extension stream wrappers:
Assuming the standard
profile is installed:
drupal_get_path('profile', 'standard') . '/config'
profile://config
core/profiles/standard/config
drupal_get_path('profile', 'standard') . '/config/install/automated_cron.settings.yml'
profile://config/install/automated_cron.settings.yml
core/profiles/standard/config/install/automated_cron.settings.yml
Assuming the node
module is enabled but color
module is not:
drupal_get_path('module', 'node') . '/config'
module://node/config
core/modules/node/config
drupal_get_path('module', 'node') . '/config/install/node.settings.yml'
module://node/config/install/node.settings.yml
core/modules/node/config/install/node.settings.yml
drupal_get_path('module', 'color') . '/config'
module://color/config
\RuntimeException
Assuming the bartik
theme is installed but seven
theme is not:
drupal_get_path('theme', 'bartik') . '/config'
theme://bartik/config
core/themes/bartik/config
drupal_get_path('theme', 'bartik') . '/color/color.inc'
theme://bartik/color/color.inc
core/themes/bartik/color/color.inc
drupal_get_path('theme', 'seven') . '/config'
theme://seven/config
\RuntimeException
New abstract class for extensions stream wrappers:
\Drupal\Core\StreamWrapper\ExtensionStreamBase
New stream wrapper classes:
\Drupal\Core\StreamWrapper\ModuleStream
\Drupal\Core\StreamWrapper\ThemeStream
\Drupal\Core\StreamWrapper\ProfileStream
None.
Needs work
10.0 β¨
Enhances developer experience.
It may affect performance, and thus requires in-depth technical reviews and profiling.
Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.