mirror of
https://github.com/flarum/core.git
synced 2025-08-10 10:24:46 +02:00
Make post types/components more flexible
This commit is contained in:
@@ -110,4 +110,19 @@ class Post extends Entity
|
||||
throw new PermissionDeniedException;
|
||||
}
|
||||
}
|
||||
|
||||
public function newFromBuilder($attributes = [])
|
||||
{
|
||||
if (!empty($attributes->type)) {
|
||||
$class = 'Flarum\Core\Posts\\'.ucfirst($attributes->type).'Post';
|
||||
if (class_exists($class)) {
|
||||
$instance = new $class;
|
||||
$instance->exists = true;
|
||||
$instance->setRawAttributes((array) $attributes, true);
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::newFromBuilder($attributes);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user