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