Skip to content

Commit 0ba36a0

Browse files
bbralamglaman
andauthored
Separate core and contrib api.php file scanning (#774)
* Add new parameters - checkCoreDeprecatedHooksInApiFiles: bool, checkContribDeprecatedHooksInApiFiles: bool * Deprecate checkDeprecatedHooksInApiFiles and make sure defaults of new parameters are set based on old one * Code now checks if a module is a core module to decide if it will load the api.php files. * Add new options to extentions.neon * Set core api.php check to true by default in bleedingEdge.neon * revert default true to check core api.php files as per original design * Update bleedingEdge.neon to enable all features * Update bleedingEdge.neon so you don't get deprecation warnings when using the defaults. * Check extension origin --------- Co-authored-by: Matt Glaman <[email protected]>
1 parent 928492b commit 0ba36a0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

bleedingEdge.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
parameters:
22
drupal:
33
bleedingEdge:
4-
checkDeprecatedHooksInApiFiles: true
4+
checkDeprecatedHooksInApiFiles: false
5+
checkCoreDeprecatedHooksInApiFiles: true
6+
checkContribDeprecatedHooksInApiFiles: true
57
rules:
68
testClassSuffixNameRule: true
79
dependencySerializationTraitPropertyRule: true

extension.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ parameters:
1919
drupal_root: '%currentWorkingDirectory%'
2020
bleedingEdge:
2121
checkDeprecatedHooksInApiFiles: false
22+
checkCoreDeprecatedHooksInApiFiles: false
23+
checkContribDeprecatedHooksInApiFiles: false
2224
rules:
2325
testClassSuffixNameRule: false
2426
dependencySerializationTraitPropertyRule: false
@@ -242,6 +244,8 @@ parametersSchema:
242244
drupal_root: string()
243245
bleedingEdge: structure([
244246
checkDeprecatedHooksInApiFiles: boolean()
247+
checkCoreDeprecatedHooksInApiFiles: boolean()
248+
checkContribDeprecatedHooksInApiFiles: boolean()
245249
])
246250
rules: structure([
247251
testClassSuffixNameRule: boolean()

src/Drupal/DrupalAutoloader.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class DrupalAutoloader
8484
public function register(Container $container): void
8585
{
8686
/**
87-
* @var array{drupal_root: string, bleedingEdge: array{checkDeprecatedHooksInApiFiles: bool}} $drupalParams
87+
* @var array{drupal_root: string, bleedingEdge: array{checkDeprecatedHooksInApiFiles: bool, checkCoreDeprecatedHooksInApiFiles: bool, checkContribDeprecatedHooksInApiFiles: bool}} $drupalParams
8888
*/
8989
$drupalParams = $container->getParameter('drupal');
9090
$drupalRoot = realpath($drupalParams['drupal_root']);
@@ -127,7 +127,14 @@ public function register(Container $container): void
127127
$this->addThemeNamespaces();
128128
$this->registerPs4Namespaces($this->namespaces);
129129
$this->loadLegacyIncludes();
130-
$checkDeprecatedHooksInApiFiles = $drupalParams['bleedingEdge']['checkDeprecatedHooksInApiFiles'];
130+
131+
// Trigger deprecation error if checkDeprecatedHooksInApiFiles is enabled.
132+
if ($drupalParams['bleedingEdge']['checkDeprecatedHooksInApiFiles']) {
133+
trigger_error('The bleedingEdge.checkDeprecatedHooksInApiFiles parameter is deprecated and will be removed in a future release.', E_USER_DEPRECATED);
134+
}
135+
$checkDeprecatedHooksInApiFiles = $drupalParams['bleedingEdge']['checkDeprecatedHooksInApiFiles'];
136+
$checkCoreDeprecatedHooksInApiFiles = $drupalParams['bleedingEdge']['checkCoreDeprecatedHooksInApiFiles'] || $checkDeprecatedHooksInApiFiles;
137+
$checkContribDeprecatedHooksInApiFiles = $drupalParams['bleedingEdge']['checkContribDeprecatedHooksInApiFiles'] || $checkDeprecatedHooksInApiFiles;
131138

132139
foreach ($this->moduleData as $extension) {
133140
$this->loadExtension($extension);
@@ -145,8 +152,13 @@ public function register(Container $container): void
145152
if (file_exists($module_dir . '/' . $module_name . '.post_update.php')) {
146153
$this->loadAndCatchErrors($module_dir . '/' . $module_name . '.post_update.php');
147154
}
148-
// Add .api.php
149-
if ($checkDeprecatedHooksInApiFiles && file_exists($module_dir . '/' . $module_name . '.api.php')) {
155+
156+
// Add .api.php for core modules
157+
if ($checkCoreDeprecatedHooksInApiFiles && $extension->origin === 'core' && file_exists($module_dir . '/' . $module_name . '.api.php')) {
158+
$this->loadAndCatchErrors($module_dir . '/' . $module_name . '.api.php');
159+
}
160+
// Add .api.php for contrib modules
161+
if ($checkContribDeprecatedHooksInApiFiles && $extension->origin !== 'core' && file_exists($module_dir . '/' . $module_name . '.api.php')) {
150162
$this->loadAndCatchErrors($module_dir . '/' . $module_name . '.api.php');
151163
}
152164
// Add misc .inc that are magically allowed via hook_hook_info.

0 commit comments

Comments
 (0)