mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
FIX: GraphQL is Missing
This commit is contained in:
parent
9a0c41500d
commit
f9b9eb6f74
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace A2nt\CMSNiceties\GraphQL;
|
namespace A2nt\CMSNiceties\GraphQL;
|
||||||
|
|
||||||
|
if (!class_exists('SilverStripe\GraphQL\TypeCreator', true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
use GraphQL\Type\Definition\ResolveInfo;
|
use GraphQL\Type\Definition\ResolveInfo;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
@ -20,18 +22,18 @@ class ElementTypeCreator extends TypeCreator
|
|||||||
public function fields()
|
public function fields()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function($object) {
|
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function ($object) {
|
||||||
return $object->ID;
|
return $object->ID;
|
||||||
}],
|
}],
|
||||||
'ID' => ['type' => Type::nonNull(Type::id())],
|
'ID' => ['type' => Type::nonNull(Type::id())],
|
||||||
'Title' => ['type' => Type::string()],
|
'Title' => ['type' => Type::string()],
|
||||||
'ParentID' => ['type' => Type::id()],
|
'ParentID' => ['type' => Type::id()],
|
||||||
'Render' => [
|
'Render' => [
|
||||||
'type' => Type::string(),
|
'type' => Type::string(),
|
||||||
'resolve' => static function($object, array $args, $context, ResolveInfo $info) {
|
'resolve' => static function ($object, array $args, $context, ResolveInfo $info) {
|
||||||
return $object->getController()->forTemplate()->HTML();
|
return $object->getController()->forTemplate()->HTML();
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace A2nt\CMSNiceties\GraphQL;
|
namespace A2nt\CMSNiceties\GraphQL;
|
||||||
|
|
||||||
|
if (!class_exists('SilverStripe\GraphQL\TypeCreator', true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
use SilverStripe\GraphQL\TypeCreator;
|
use SilverStripe\GraphQL\TypeCreator;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace A2nt\CMSNiceties\GraphQL;
|
namespace A2nt\CMSNiceties\GraphQL;
|
||||||
|
|
||||||
|
if (!class_exists('SilverStripe\GraphQL\TypeCreator', true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
use GraphQL\Type\Definition\ResolveInfo;
|
use GraphQL\Type\Definition\ResolveInfo;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
@ -26,90 +28,90 @@ class PageTypeCreator extends TypeCreator
|
|||||||
|
|
||||||
public function fields()
|
public function fields()
|
||||||
{
|
{
|
||||||
$elementsConnection = Connection::create('Elements')
|
$elementsConnection = Connection::create('Elements')
|
||||||
->setConnectionType($this->manager->getType('element'))
|
->setConnectionType($this->manager->getType('element'))
|
||||||
->setDescription('A list of the page elements')
|
->setDescription('A list of the page elements')
|
||||||
->setSortableFields(['ID', 'Title']);
|
->setSortableFields(['ID', 'Title']);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function($object) {
|
'_id' => ['type' => Type::nonNull(Type::id()),'resolve' => static function ($object) {
|
||||||
return $object->ID;
|
return $object->ID;
|
||||||
}],
|
}],
|
||||||
'ID' => ['type' => Type::nonNull(Type::id())],
|
'ID' => ['type' => Type::nonNull(Type::id())],
|
||||||
'Title' => ['type' => Type::string()],
|
'Title' => ['type' => Type::string()],
|
||||||
'Content' => ['type' => Type::string()],
|
'Content' => ['type' => Type::string()],
|
||||||
'Link' => ['type' => Type::string(), 'resolve' => static function($object) {
|
'Link' => ['type' => Type::string(), 'resolve' => static function ($object) {
|
||||||
return $object->Link();
|
return $object->Link();
|
||||||
}],
|
}],
|
||||||
'URLSegment' => ['type' => Type::string()],
|
'URLSegment' => ['type' => Type::string()],
|
||||||
'ParentID' => ['type' => Type::id()],
|
'ParentID' => ['type' => Type::id()],
|
||||||
'ClassName' => ['type' => Type::string()],
|
'ClassName' => ['type' => Type::string()],
|
||||||
'CSSClass' => ['type' => Type::string(), 'resolve' => static function($object) {
|
'CSSClass' => ['type' => Type::string(), 'resolve' => static function ($object) {
|
||||||
return $object->CSSClass();
|
return $object->CSSClass();
|
||||||
}],
|
}],
|
||||||
'Summary' => ['type' => Type::string(), 'resolve' => static function($object) {
|
'Summary' => ['type' => Type::string(), 'resolve' => static function ($object) {
|
||||||
return $object->Summary();
|
return $object->Summary();
|
||||||
}],
|
}],
|
||||||
'HTML' => ['type' => Type::string(), 'resolve' => static function($object) {
|
'HTML' => ['type' => Type::string(), 'resolve' => static function ($object) {
|
||||||
// get action from request
|
// get action from request
|
||||||
$action = null;
|
$action = null;
|
||||||
|
|
||||||
/** @var \Page $object */
|
/** @var \Page $object */
|
||||||
Director::set_current_page($object);
|
Director::set_current_page($object);
|
||||||
/** @var \PageController $controller */
|
/** @var \PageController $controller */
|
||||||
$controller = ModelAsController::controller_for($object);
|
$controller = ModelAsController::controller_for($object);
|
||||||
|
|
||||||
// find templates
|
// find templates
|
||||||
$tpl = 'Page';
|
$tpl = 'Page';
|
||||||
$tpls = SSViewer::get_templates_by_class(
|
$tpls = SSViewer::get_templates_by_class(
|
||||||
$object->ClassName,
|
$object->ClassName,
|
||||||
($action ? '_'.$action : ''),
|
($action ? '_'.$action : ''),
|
||||||
\Page::class
|
\Page::class
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($tpls as $tpl){
|
foreach ($tpls as $tpl) {
|
||||||
if(is_array($tpl)){
|
if (is_array($tpl)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$a_tpl = explode('\\',$tpl);
|
$a_tpl = explode('\\', $tpl);
|
||||||
$last_name = array_pop($a_tpl);
|
$last_name = array_pop($a_tpl);
|
||||||
$a_tpl[] = 'Layout';
|
$a_tpl[] = 'Layout';
|
||||||
$a_tpl[] = $last_name;
|
$a_tpl[] = $last_name;
|
||||||
$a_tpl = implode('\\', $a_tpl);
|
$a_tpl = implode('\\', $a_tpl);
|
||||||
|
|
||||||
if(SSViewer::hasTemplate($a_tpl)){
|
if (SSViewer::hasTemplate($a_tpl)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
||||||
$tpl = ($tpl !== 'Page') ? $tpl : 'Layout/Page';
|
$tpl = ($tpl !== 'Page') ? $tpl : 'Layout/Page';
|
||||||
|
|
||||||
$action = $action ? $action : 'index';
|
$action = $action ? $action : 'index';
|
||||||
/** @var HTTPRequest $request */
|
/** @var HTTPRequest $request */
|
||||||
$request = new HTTPRequest('GET', $object->AbsoluteLink());
|
$request = new HTTPRequest('GET', $object->AbsoluteLink());
|
||||||
$request->setSession(new Session([]));
|
$request->setSession(new Session([]));
|
||||||
|
|
||||||
// a little dirty way to make forms working
|
// a little dirty way to make forms working
|
||||||
Controller::curr()->config()->set('url_segment', $object->AbsoluteLink());
|
Controller::curr()->config()->set('url_segment', $object->AbsoluteLink());
|
||||||
/*$controller->setRequest($request);*/
|
/*$controller->setRequest($request);*/
|
||||||
//$request->getSession()->init($request);
|
//$request->getSession()->init($request);
|
||||||
|
|
||||||
$controller->setRequest($request);
|
$controller->setRequest($request);
|
||||||
$controller->setAction($action);
|
$controller->setAction($action);
|
||||||
//$controller->pushCurrent();
|
//$controller->pushCurrent();
|
||||||
$controller->doInit();
|
$controller->doInit();
|
||||||
|
|
||||||
$layout = $controller->renderWith($tpl);
|
$layout = $controller->renderWith($tpl);
|
||||||
return $controller
|
return $controller
|
||||||
->customise(['Layout' => $layout])
|
->customise(['Layout' => $layout])
|
||||||
->renderWith('GraphQLPage')->HTML();
|
->renderWith('GraphQLPage')->HTML();
|
||||||
}],
|
}],
|
||||||
'Elements' => [
|
'Elements' => [
|
||||||
'type' => $elementsConnection->toType(),
|
'type' => $elementsConnection->toType(),
|
||||||
'args' => $elementsConnection->args(),
|
'args' => $elementsConnection->args(),
|
||||||
'resolve' => static function($object, array $args, $context, ResolveInfo $info) use ($elementsConnection) {
|
'resolve' => static function ($object, array $args, $context, ResolveInfo $info) use ($elementsConnection) {
|
||||||
return $elementsConnection->resolveList(
|
return $elementsConnection->resolveList(
|
||||||
$object->ElementalArea()->Elements(),
|
$object->ElementalArea()->Elements(),
|
||||||
$args,
|
$args,
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace A2nt\CMSNiceties\GraphQL;
|
namespace A2nt\CMSNiceties\GraphQL;
|
||||||
|
|
||||||
|
if (!class_exists('SilverStripe\GraphQL\Pagination\PaginatedQueryCreator', true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
use GraphQL\Type\Definition\ResolveInfo;
|
use GraphQL\Type\Definition\ResolveInfo;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace A2nt\CMSNiceties\GraphQL;
|
namespace A2nt\CMSNiceties\GraphQL;
|
||||||
|
|
||||||
|
if (!class_exists('SilverStripe\GraphQL\Pagination\PaginatedQueryCreator', true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
use GraphQL\Type\Definition\ResolveInfo;
|
use GraphQL\Type\Definition\ResolveInfo;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
@ -21,32 +23,32 @@ class PaginatedReadPagesQueryCreator extends PaginatedQueryCreator
|
|||||||
return Connection::create('readPages')
|
return Connection::create('readPages')
|
||||||
->setConnectionType($this->manager->getType('page'))
|
->setConnectionType($this->manager->getType('page'))
|
||||||
->setArgs([
|
->setArgs([
|
||||||
'Link' => [
|
'Link' => [
|
||||||
'type' => Type::string()
|
'type' => Type::string()
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
->setSortableFields(['Sort'])
|
->setSortableFields(['Sort'])
|
||||||
->setConnectionResolver(static function ($object, array $args, $context, ResolveInfo $info) {
|
->setConnectionResolver(static function ($object, array $args, $context, ResolveInfo $info) {
|
||||||
|
|
||||||
if (isset($args['Link'])) {
|
if (isset($args['Link'])) {
|
||||||
$link = $args['Link'];
|
$link = $args['Link'];
|
||||||
|
|
||||||
if(SiteTree::has_extension('\TractorCow\Fluent\Extension\FluentSiteTreeExtension')) {
|
if (SiteTree::has_extension('\TractorCow\Fluent\Extension\FluentSiteTreeExtension')) {
|
||||||
$arr = array_filter(explode('/', $args['Link']));
|
$arr = array_filter(explode('/', $args['Link']));
|
||||||
|
|
||||||
$locale = \TractorCow\Fluent\Model\Locale::get()->filter('URLSegment', array_shift($arr))->first();
|
$locale = \TractorCow\Fluent\Model\Locale::get()->filter('URLSegment', array_shift($arr))->first();
|
||||||
\TractorCow\Fluent\State\FluentState::singleton()->setLocale($locale->Locale);
|
\TractorCow\Fluent\State\FluentState::singleton()->setLocale($locale->Locale);
|
||||||
|
|
||||||
$link = implode('/', $arr);
|
$link = implode('/', $arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$list = ArrayList::create();
|
$list = ArrayList::create();
|
||||||
$page = SiteTree::get_by_link($link);
|
$page = SiteTree::get_by_link($link);
|
||||||
$list->add($page);
|
$list->add($page);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*$list = \Page::get();
|
/*$list = \Page::get();
|
||||||
|
|
||||||
// Optional filtering by properties
|
// Optional filtering by properties
|
||||||
if (isset($args['ID'])) {
|
if (isset($args['ID'])) {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace A2nt\CMSNiceties\GraphQL;
|
namespace A2nt\CMSNiceties\GraphQL;
|
||||||
|
|
||||||
|
if (!class_exists('SilverStripe\GraphQL\QueryCreator', true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
use GraphQL\Type\Definition\ResolveInfo;
|
use GraphQL\Type\Definition\ResolveInfo;
|
||||||
use GraphQL\Type\Definition\Type;
|
use GraphQL\Type\Definition\Type;
|
||||||
|
Loading…
Reference in New Issue
Block a user