1
0
mirror of https://github.com/flarum/core.git synced 2025-08-28 02:20:14 +02:00

Added post extender with type method, deprecated ConfigurePostTypes (#2101)

This commit is contained in:
Alexander Skvortsov
2020-11-03 10:43:49 -05:00
committed by GitHub
parent 5842dd1200
commit cee87848fe
6 changed files with 106 additions and 5 deletions

39
src/Extend/Post.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Extend;
use Flarum\Extension\Extension;
use Flarum\Post\Post as PostModel;
use Illuminate\Contracts\Container\Container;
class Post implements ExtenderInterface
{
private $postTypes = [];
/**
* Register a new post type. This is generally done for custom 'event posts',
* such as those that appear when a discussion is renamed.
*
* @param string $postType: The ::class attribute of the custom Post type that is being added.
*/
public function type(string $postType)
{
$this->postTypes[] = $postType;
return $this;
}
public function extend(Container $container, Extension $extension = null)
{
foreach ($this->postTypes as $postType) {
PostModel::setModel($postType::$type, $postType);
}
}
}