diff --git a/_config/blocks.yml b/_config/blocks.yml index 6fb8460..5211f8f 100644 --- a/_config/blocks.yml +++ b/_config/blocks.yml @@ -17,6 +17,6 @@ SiteConfig: - BlockSiteConfigExtension Block: + defaultBlockArea: false extensions: - Versioned('Stage','Live') - diff --git a/code/dataobjects/Block.php b/code/dataobjects/Block.php index 1901965..2f582c7 100644 --- a/code/dataobjects/Block.php +++ b/code/dataobjects/Block.php @@ -257,6 +257,16 @@ public function onAfterDuplicate() $this->BlockSets()->removeAll(); } + public function onBeforeWrite() + { + $defaultBlockArea = Block::config()->get('defaultBlockArea'); + $blockArea = $this->getField('ManyMany[BlockArea]'); + if ($defaultBlockArea !== false && $blockArea === null) { + $this->setField('ManyMany[BlockArea]', $defaultBlockArea); + } + parent::onBeforeWrite(); + } + /* * Base permissions */