#3521811: Move drupalSettings and Drupal to a utility module in the frontend
Merge request reports
Activity
mentioned in merge request !954 (merged)
- ui/src/utils/drupal-globals.ts 0 → 100644
1 const { Drupal, drupalSettings } = window as any; That's what I suggested initially. I went with a simple module, because I thought there's no good reason to tie an API to React which has nothing do to with it. Adding hooks would mean a bit more refactoring, because they can only be used at top level of components (or in other hooks), no calls inside conditions etc. With that said, it's not a huge lift, and I don't feel strongly that we shouldn't do that — it's definitely a more elegant consumption of those values.
So I'm fine either way!
added 44 commits
-
68ffacd8...8279a0ae - 43 commits from branch
project:0.x
- 90809f60 - Merge branch '0.x' into 3521811-drupal-globals-utility
-
68ffacd8...8279a0ae - 43 commits from branch
added 3 commits
- Resolved by Harumi Jang
94 95 const store = makeStore({ configuration: appConfiguration }); 95 96 96 97 // Make the store available to extensions. 97 98 (drupalSettings as any).xb.store = store; changed this line in version 3 of the diff
28 29 drupalSettings?.xb.globalAssets.jsHeader + component.js_header; 29 30 30 31 const markup = component.default_markup; 31 32 const base_url = window.location.origin + drupalSettings?.path.baseUrl; changed this line in version 3 of the diff
42 43 baseUrl: drupalSettings?.path?.baseUrl || import.meta.env.BASE_URL, 43 44 entityType: drupalSettings?.xb?.entityType || 'node', 44 45 entity: drupalSettings?.xb?.entity || '1', 45 46 devMode: drupalSettings?.xb?.devMode || false, changed this line in version 3 of the diff
10 11 11 12 const ExtensionsList: React.FC<ExtensionsPopoverProps> = () => { 12 13 let extensionsList = []; 13 14 if (drupalSettings && drupalSettings.xbExtension) { 14 extensionsList = Object.values(drupalSettings.xbExtension).map((value) => { 15 return { 16 ...value, 17 imgSrc: 18 value.imgSrc || 19 `${drupalSettings.path.baseUrl}${drupalSettings.xb.xbModulePath}/ui/assets/icons/extension-default-abstract.svg`, 20 name: value.name, 21 description: value.description, 22 }; 23 }); 15 extensionsList = Object.values(drupalSettings.xbExtension).map( 16 (value: any) => { It's not necessary to set the
: any
. if you set up thegetDrupalSettings
ts definition to return: DrupalSettings
. This will result in having to expand theDrupalSettings
interface in global.d.ts, but nothing too major and it kinda fits in the spirit of why this issue exists in the first place.changed this line in version 3 of the diff
added 11 commits
-
b04726b2...765e31ba - 9 commits from branch
project:0.x
- f3b1a352 - Merge branch '0.x' into 3521811-drupal-globals-utility
- e2b23514 - Address feedback
-
b04726b2...765e31ba - 9 commits from branch
- ui/src/types/FormatType.ts 0 → 100644
1 export interface FormatType { moved this out to its own type file since its now being used in
DrupalSettings.ts
Edited by Harumi Jang
requested review from @bnjmnm
added 5 commits
-
1114f705...a4711f03 - 4 commits from branch
project:0.x
- 000e2ef9 - Merge branch '0.x' into 3521811-drupal-globals-utility
-
1114f705...a4711f03 - 4 commits from branch
requested review from @balintbrews, @larowlan, and @jessebaker
added 7 commits
-
000e2ef9...5592644d - 6 commits from branch
project:0.x
- f6fa5e65 - Merge branch '0.x' into 3521811-drupal-globals-utility
-
000e2ef9...5592644d - 6 commits from branch