Initial import of space_profiles module
This commit is contained in:
26
components/TemplateRegistry.php
Normal file
26
components/TemplateRegistry.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\space_profiles\components;
|
||||
|
||||
use Yii;
|
||||
|
||||
class TemplateRegistry
|
||||
{
|
||||
public const TEMPLATE_RESCUE_CENTER = 'rescue_center';
|
||||
|
||||
public static function options(): array
|
||||
{
|
||||
return [
|
||||
self::TEMPLATE_RESCUE_CENTER => Yii::t('SpaceProfilesModule.base', 'Rescue Center (Default)'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function resolveView(?string $templateKey): string
|
||||
{
|
||||
if ($templateKey === self::TEMPLATE_RESCUE_CENTER || empty($templateKey)) {
|
||||
return 'templates/rescue-center';
|
||||
}
|
||||
|
||||
return 'templates/rescue-center';
|
||||
}
|
||||
}
|
||||
74
components/UrlRule.php
Normal file
74
components/UrlRule.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\space_profiles\components;
|
||||
|
||||
use humhub\components\ContentContainerUrlRuleInterface;
|
||||
use humhub\modules\content\components\ContentContainerActiveRecord;
|
||||
use yii\base\Component;
|
||||
use yii\web\UrlManager;
|
||||
use yii\web\UrlRuleInterface;
|
||||
|
||||
class UrlRule extends Component implements UrlRuleInterface, ContentContainerUrlRuleInterface
|
||||
{
|
||||
public const CONTAINER_ROUTE = 'space_profiles/profile/view';
|
||||
public const PUBLIC_ROUTE = 'space_profiles/public/view';
|
||||
private const ROUTE_SEGMENT = 'rescues';
|
||||
|
||||
public function parseContentContainerRequest(ContentContainerActiveRecord $container, UrlManager $manager, string $containerUrlPath, array $urlParams)
|
||||
{
|
||||
if ($containerUrlPath === self::ROUTE_SEGMENT) {
|
||||
return [self::CONTAINER_ROUTE, $urlParams];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function createContentContainerUrl(UrlManager $manager, string $containerUrlPath, string $route, array $params)
|
||||
{
|
||||
if ($route !== self::CONTAINER_ROUTE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = $containerUrlPath . '/' . self::ROUTE_SEGMENT;
|
||||
if (!empty($params)) {
|
||||
$query = http_build_query($params);
|
||||
if ($query !== '') {
|
||||
$url .= '?' . $query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function createUrl($manager, $route, $params)
|
||||
{
|
||||
if ($route !== self::PUBLIC_ROUTE || empty($params['slug'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$slug = urlencode((string)$params['slug']);
|
||||
unset($params['slug']);
|
||||
|
||||
$url = self::ROUTE_SEGMENT . '/' . $slug;
|
||||
if (!empty($params) && ($query = http_build_query($params)) !== '') {
|
||||
$url .= '?' . $query;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function parseRequest($manager, $request)
|
||||
{
|
||||
$path = trim($request->getPathInfo(), '/');
|
||||
if (strpos($path, self::ROUTE_SEGMENT . '/') !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parts = explode('/', $path);
|
||||
if (empty($parts[1])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return [self::PUBLIC_ROUTE, ['slug' => urldecode($parts[1])]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user