column-block-compatibility.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const updatingBlock = ['core/group'];
  2. wp.hooks.addFilter(
  3. 'blocks.registerBlockType',
  4. 'astra/meta/groupLayoutSettings',
  5. (settings, name) => {
  6. if (!updatingBlock.includes(name)) {
  7. return settings;
  8. }
  9. const newSettings = {
  10. ...settings,
  11. supports: {
  12. ...(settings.supports || {}),
  13. layout: {
  14. ...(settings.supports.layout || {}),
  15. allowEditing: true,
  16. allowSwitching: false,
  17. allowInheriting: true,
  18. },
  19. __experimentalLayout: {
  20. ...(settings.supports.__experimentalLayout || {}),
  21. allowEditing: true,
  22. allowSwitching: false,
  23. allowInheriting: true,
  24. },
  25. },
  26. };
  27. return newSettings;
  28. },
  29. 20
  30. );
  31. wp.hooks.addFilter(
  32. 'blocks.getBlockAttributes',
  33. 'astra/groupBlockSetting/checkInheritOption',
  34. (attributes, blockType) => {
  35. if (!updatingBlock.includes(blockType.name)) {
  36. return attributes;
  37. }
  38. if (blockType.name == 'core/group' && undefined != attributes.layout && false == attributes.layout.inherit ) {
  39. return attributes;
  40. }
  41. attributes = {
  42. ...attributes,
  43. layout: {
  44. inherit: true,
  45. },
  46. };
  47. return attributes;
  48. }
  49. );
  50. /**
  51. * Set "Inherit default layout" option enable by default for Group block.
  52. *
  53. * Also set "Full Width" layout by default on drag-drop for following blocks.
  54. */
  55. wp.blocks.registerBlockVariation(
  56. 'core/group',
  57. {
  58. isDefault: true,
  59. attributes: {
  60. layout: {
  61. inherit: true,
  62. },
  63. align: 'full'
  64. },
  65. }
  66. );
  67. wp.blocks.registerBlockVariation(
  68. 'core/cover',
  69. {
  70. isDefault: true,
  71. attributes: {
  72. align: 'full'
  73. },
  74. }
  75. );