IMPR: GraphQL helpers

This commit is contained in:
Tony Air 2023-10-24 22:00:52 +02:00
parent a167ad4b5d
commit 39f81b5a16
2 changed files with 39 additions and 0 deletions

View File

@ -53,3 +53,4 @@ Page:
- A2nt\CMSNiceties\Models\TeamMember - A2nt\CMSNiceties\Models\TeamMember
extensions: extensions:
- DNADesign\Elemental\Extensions\ElementalPageExtension - DNADesign\Elemental\Extensions\ElementalPageExtension
- ObjectGraphQlEx

View File

@ -0,0 +1,38 @@
<?php
namespace A2nt\CMSNiceties\Extensions;
use SilverStripe\Control\Controller;
use SilverStripe\GraphQL\Controller as GraphQLController;
use App\GraphQL\URLLinkablePlugin;
use SilverStripe\ORM\DataExtension;
/**
* Class \A2nt\CMSNiceties\Extensions\SubmittedFormEx
* AJAX/GraphQL helpers
* @property \A2nt\CMSNiceties\Extensions\SubmittedFormEx $owner
*/
class ObjectGraphQlEx extends DataExtension
{
// Get rendered template
public function MainContent()
{
$object = $this;
return isset($object->GraphQLContent) ? $object->GraphQLContent : null;
}
public function RequestLink()
{
$curr = Controller::curr();
//$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];
}
}
return null;
}
}