AmeliaBookingButtonRendererTrait.php
2 months ago
AmeliaBookingModule.php
7 months ago
AmeliaCatalogBookingModule.php
1 month ago
AmeliaCatalogModule.php
7 months ago
AmeliaCustomerPanelModule.php
7 months ago
AmeliaEmployeePanelModule.php
7 months ago
AmeliaEventsCalendarModule.php
1 month ago
AmeliaEventsListBookingButtonModule.php
2 months ago
AmeliaEventsListModule.php
1 month ago
AmeliaEventsModule.php
7 months ago
AmeliaSearchModule.php
7 months ago
AmeliaStepBookingButtonModule.php
2 months ago
AmeliaStepBookingModule.php
1 month ago
ModuleMetadata.php
1 month ago
SharedShortcodeModule.php
1 month ago
index.php
1 month ago
ModuleMetadata.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Divi5Amelia; |
| 4 | |
| 5 | /** |
| 6 | * Helpers for merging module.json with shared-module.json for Divi 5 registration. |
| 7 | */ |
| 8 | class ModuleMetadata |
| 9 | { |
| 10 | /** |
| 11 | * Merge shared attributes into module registration args. |
| 12 | * |
| 13 | * @param string $moduleFolder Absolute path to the module directory containing module.json. |
| 14 | * @param array $args Extra arguments passed to ModuleRegistration::register_module(). |
| 15 | * |
| 16 | * @return array Registration args with merged attributes. |
| 17 | */ |
| 18 | public static function getRegistrationArgs(string $moduleFolder, array $args = []): array |
| 19 | { |
| 20 | $moduleFolder = untrailingslashit($moduleFolder); |
| 21 | $moduleFile = $moduleFolder . '/module.json'; |
| 22 | $sharedFile = dirname($moduleFolder, 2) . '/shared-module.json'; |
| 23 | |
| 24 | if (! is_readable($moduleFile)) { |
| 25 | return $args; |
| 26 | } |
| 27 | |
| 28 | $moduleMetadata = json_decode(file_get_contents($moduleFile), true); |
| 29 | |
| 30 | if (! is_array($moduleMetadata)) { |
| 31 | return $args; |
| 32 | } |
| 33 | |
| 34 | $sharedMetadata = []; |
| 35 | |
| 36 | if (is_readable($sharedFile)) { |
| 37 | $decoded = json_decode(file_get_contents($sharedFile), true); |
| 38 | if (is_array($decoded)) { |
| 39 | $sharedMetadata = $decoded; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | $moduleAttributes = $moduleMetadata['attributes'] ?? []; |
| 44 | $sharedAttributes = $sharedMetadata['attributes'] ?? []; |
| 45 | $mergedAttributes = array_merge($sharedAttributes, $moduleAttributes); |
| 46 | |
| 47 | return array_merge($args, ['attributes' => $mergedAttributes]); |
| 48 | } |
| 49 | } |
| 50 |