This commit is contained in:
Bastian Allgeier
2020-07-07 12:40:13 +02:00
parent 5f025ac2c2
commit f79d2e960c
176 changed files with 10532 additions and 5343 deletions

View File

@@ -31,13 +31,17 @@ trait SiteActions
*/
protected function commit(string $action, array $arguments, Closure $callback)
{
$old = $this->hardcopy();
$kirby = $this->kirby();
$old = $this->hardcopy();
$kirby = $this->kirby();
$argumentValues = array_values($arguments);
$this->rules()->$action(...$argumentValues);
$kirby->trigger('site.' . $action . ':before', $arguments);
$result = $callback(...$argumentValues);
$kirby->trigger('site.' . $action . ':after', ['newSite' => $result, 'oldSite' => $old]);
$this->rules()->$action(...$arguments);
$kirby->trigger('site.' . $action . ':before', ...$arguments);
$result = $callback(...$arguments);
$kirby->trigger('site.' . $action . ':after', $result, $old);
$kirby->cache('pages')->flush();
return $result;
}
@@ -51,7 +55,8 @@ trait SiteActions
*/
public function changeTitle(string $title, string $languageCode = null)
{
return $this->commit('changeTitle', [$this, $title, $languageCode], function ($site, $title, $languageCode) {
$arguments = ['site' => $this, 'title' => $title, 'languageCode' => $languageCode];
return $this->commit('changeTitle', $arguments, function ($site, $title, $languageCode) {
return $site->save(['title' => $title], $languageCode);
});
}