mirror of
https://github.com/a2nt/cms-niceties.git
synced 2024-10-22 11:05:46 +02:00
IMPR: Load extra resources on GraphQL
This commit is contained in:
parent
0efa3b0580
commit
7920ba81c7
@ -15,6 +15,8 @@ Page:
|
||||
type: String
|
||||
RequestLink:
|
||||
type: String
|
||||
Resources:
|
||||
type: String
|
||||
children: "[Page]"
|
||||
elementalArea:
|
||||
type: ElementalArea
|
||||
|
@ -9,6 +9,8 @@ use SilverStripe\Forms\TextareaField;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
|
||||
use TractorCow\Fluent\Extension\FluentSiteTreeExtension;
|
||||
|
||||
/**
|
||||
* Class \A2nt\CMSNiceties\Extensions\SiteTreeExtension
|
||||
*
|
||||
@ -137,5 +139,12 @@ class SiteTreeExtension extends DataExtension
|
||||
// h1 page title and navigation label should be equal for SEO
|
||||
$obj = $this->owner;
|
||||
$obj->setField('MenuTitle', $obj->getField('Title'));
|
||||
|
||||
if (class_exists(FluentSiteTreeExtension::class) && ! $obj->isDraftedInLocale() && $obj->isInDB()) {
|
||||
$elementalArea = $obj->ElementalArea();
|
||||
|
||||
$elementalAreaNew = $elementalArea->duplicate();
|
||||
$obj->setField('ElementalAreaID', $elementalAreaNew->ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,17 @@
|
||||
|
||||
namespace A2nt\CMSNiceties\GraphQL;
|
||||
|
||||
use A2nt\CMSNiceties\Templates\DeferredRequirements;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\GraphQL\Controller as GraphQLController;
|
||||
use App\GraphQL\URLLinkablePlugin;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
/**
|
||||
* Class \A2nt\CMSNiceties\Extensions\SubmittedFormEx
|
||||
* Class \A2nt\CMSNiceties\GraphQL\ObjectGraphQlEx
|
||||
* AJAX/GraphQL helpers
|
||||
* @property \A2nt\CMSNiceties\Extensions\SubmittedFormEx $owner
|
||||
*/
|
||||
class ObjectGraphQlEx extends DataExtension
|
||||
class ObjectGraphQlEx extends Extension
|
||||
{
|
||||
// Get rendered template
|
||||
public function MainContent()
|
||||
@ -21,15 +21,36 @@ class ObjectGraphQlEx extends DataExtension
|
||||
return isset($object->GraphQLContent) ? $object->GraphQLContent : null;
|
||||
}
|
||||
|
||||
public function Resources()
|
||||
{
|
||||
$object = $this->owner;
|
||||
$res = $object->config()->get('graphql_resources');
|
||||
return $res ? json_encode($res) : null;
|
||||
}
|
||||
|
||||
public function RequestLink()
|
||||
{
|
||||
$curr = Controller::curr();
|
||||
$req = $curr->getRequest();
|
||||
|
||||
//$var = URLLinkablePlugin::config()->get('single_field_name');
|
||||
$var = 'url';
|
||||
if ($curr::class === GraphQLController::class) {
|
||||
$vars = json_decode($curr->getRequest()->getBody(), true)['variables'];
|
||||
if (isset($vars[$var])) {
|
||||
return $vars[$var];
|
||||
$link = $vars[$var];
|
||||
|
||||
if ($req->requestVar('SecurityID')) {
|
||||
$urlArray = explode('/', $link);
|
||||
$urlArray = array_filter($urlArray);
|
||||
|
||||
// remove last element
|
||||
array_pop($urlArray);
|
||||
|
||||
$link = '/'.implode('/', $urlArray).'/';
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user