Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created April 5, 2016 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hailwood/552002caab446f3afcf95b2f3acca201 to your computer and use it in GitHub Desktop.
Save hailwood/552002caab446f3afcf95b2f3acca201 to your computer and use it in GitHub Desktop.
protected function onBeforeWrite()
{
parent::onBeforeWrite();
foreach ($this->record as $key => $value) {
if (preg_match('/Geocontent\[(.+)\]/', $key, $matches)) {
if (!$value) {
$block = $this->GeoContentBlocks()->filter('Code', $matches[1])->first();
if ($block && $block->exists()) {
$block->delete();
}
} else {
$block = $this->GeoContent($matches[1], true);
$block->Content = $value;
$block->write();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment