Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created March 22, 2015 03:31
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/39c5dff8da55f90249fa to your computer and use it in GitHub Desktop.
Save hailwood/39c5dff8da55f90249fa to your computer and use it in GitHub Desktop.
<?php
//...
public function onBeforeWrite() {
$file = $this->File();
$fileChanged = false;
foreach (['Title' => 'Title', 'Filename' => 'Name'] as $field => $fileMethod) {
if ($this->isChanged($field)) {
$fileChanged = true;
$file->{$fileMethod} = $this->getField($field);
}
}
if ($fileChanged) {
$file->write();
}
parent::onBeforeWrite();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment