Skip to content

Commit

Permalink
Set the title before validating for new Assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Mar 21, 2017
1 parent a29666d commit 1b32c08
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ public function beforeValidate()
$this->kind = AssetsHelper::getFileKindByExtension($this->filename);
}

if (!$this->id && (!$this->title || $this->title === Craft::t('app', 'New Element'))) {
// Give it a default title based on the file name
$this->title = StringHelper::toTitleCase(pathinfo($this->filename, PATHINFO_FILENAME));
}

return parent::beforeValidate();
}

Expand Down Expand Up @@ -1089,12 +1094,6 @@ public function beforeSave(bool $isNew): bool
$this->tempFilePath = null;
}

// todo: find a better way to do this
if ($isNew && (!$this->title || $this->title === Craft::t('app', 'New Element'))) {
// Give it a default title based on the file name
$this->title = StringHelper::toTitleCase(pathinfo($this->filename, PATHINFO_FILENAME));
}

return parent::beforeSave($isNew);
}

Expand Down

0 comments on commit 1b32c08

Please sign in to comment.