-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8af1b3c
Showing
33 changed files
with
1,493 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
content_revisions: TRUE | ||
asset_revisions: TRUE | ||
storage_location: ../html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Quant API | ||
description: Connect to the hosted Quant service | ||
package: Quant | ||
|
||
type: module | ||
core: 8.x | ||
|
||
dependencies: | ||
- drupal:quant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
quant_api.settings_form: | ||
title: 'Quant API' | ||
route_name: quant_api.settings_form | ||
description: 'API connectivity with the hosted Quant service' | ||
parent: quant | ||
weight: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
quant_api.settings_form: | ||
path: '/admin/config/development/quant/api' | ||
defaults: | ||
_form: '\Drupal\quant_api\Form\SettingsForm' | ||
_title: 'Quant API Configuration' | ||
requirements: | ||
_permission: 'access administration pages' | ||
options: | ||
_admin_route: TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
services: | ||
quant_api.client: | ||
class: Drupal\quant_api\Client\QuantClient | ||
arguments: | ||
- '@http_client' | ||
- '@config.factory' | ||
|
||
quant.output.api: | ||
class: Drupal\quant_api\EventSubscriber\QuantApi | ||
arguments: | ||
- '@quant_api.client' | ||
tags: | ||
- { name: 'event_subscriber' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Drupal\quant_api\Client; | ||
|
||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
use GuzzleHttp\Client; | ||
|
||
|
||
class QuantClient implements QuantClientInterface { | ||
|
||
/** | ||
* Build the QuantClient instance. | ||
*/ | ||
public function __construct(Client $client, ConfigFactoryInterface $config_factory) { | ||
$config = $config_factory->get('quant_api.settings'); | ||
$this->client = $client; | ||
// @TODO: Grab API connection details from the config. | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function ping() : bool { | ||
return TRUE; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function send(array $data) : bool { | ||
return TRUE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Drupal\quant_api\Client; | ||
|
||
/** | ||
* Describe what the Quant client looks like. | ||
*/ | ||
interface QuantClientInterface { | ||
|
||
/** | ||
* Test the connection to the API controller. | ||
* | ||
* @return bool | ||
* If API credentials can | ||
*/ | ||
public function ping() : bool; | ||
|
||
/** | ||
* Send a payload to the API. | ||
* | ||
* @param array $data | ||
* The data array to send. | ||
* | ||
* @return bool | ||
* If the request was successful | ||
* | ||
* @TODO: Error handlers :D | ||
* @throws \Drupal\quant_api\Error\InvalidPayload | ||
* @throws \Drupal\quant_api\Error\InvalidResposne | ||
*/ | ||
public function send(array $data) : bool; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Drupal\quant_api\EventSubscriber; | ||
|
||
use Drupal\quant\Event\QuantEvent; | ||
use Drupal\quant_api\Client\QuantClientInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Integrate with the QuantAPI to store static assets. | ||
*/ | ||
class QuantApi implements EventSubscriberInterface { | ||
|
||
/** | ||
* The HTTP client to make API requests. | ||
* | ||
* @var \Drupal\quant_api\Client\QuantClientInterface; | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* QuantAPI event subcsriber. | ||
* | ||
* Listens to Quant events and triggers requests to the configured | ||
* API endpoint for different operations. | ||
* | ||
* @param \Drupal\quant_api\Client\QuantClientInterface $client | ||
* The Drupal HTTP Client to make requests. | ||
*/ | ||
public function __construct(QuantClientInterface $client) { | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
$events[QuantEvent::OUTPUT][] = ['onOutput']; | ||
return $events; | ||
} | ||
|
||
/** | ||
* Trigger an API request with the event data. | ||
* | ||
* @param Drupal\quant\Event\QuantEvent $event | ||
* The event. | ||
*/ | ||
public function onOutput(QuantEvent $event) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Drupal\quant_api\Form; | ||
|
||
use Drupal\Core\Form\ConfigFormBase; | ||
use Drupal\Core\Form\FormStateInterface; | ||
use Drupal\quant_api\Client\QuantClientInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Quant configuration form. | ||
* | ||
* @see Drupal\Core\Form\ConfigFormBase | ||
*/ | ||
class SettingsForm extends ConfigFormBase { | ||
|
||
const SETTINGS = 'quant_api.settings'; | ||
|
||
/** | ||
* Build the form. | ||
*/ | ||
public function __construct(QuantClientInterface $client) { | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('quant_api.client') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormId() { | ||
return 'quant_api_settings'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getEditableConfigNames() { | ||
return [ | ||
self::SETTINGS, | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state) { | ||
$config = $this->config(self::SETTINGS); | ||
|
||
if ($config->get('api_token')) { | ||
if ($this->client->ping()) { | ||
$form['api_status'] = [ | ||
'#markup' => $this->t('Successfully connected to the API'), | ||
]; | ||
} | ||
else { | ||
$form['api_status'] = [ | ||
'#markup' => $this->t('Cannot connect to the API'), | ||
]; | ||
} | ||
} | ||
|
||
$form['api_token'] = [ | ||
'#type' => 'textfield', | ||
'#title' => $this->t('API Token'), | ||
]; | ||
|
||
// @TODO QUANT API CONFIGURATION... | ||
|
||
return parent::buildForm($form, $form_state); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: Quant | ||
description: Quant content export | ||
package: Quant | ||
|
||
type: module | ||
core: 8.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
quant: | ||
title: 'Quant' | ||
route_name: quant.config | ||
description: 'Configuration for the quant static exporter' | ||
parent: system.admin_config | ||
weight: 10 | ||
|
||
quant.config: | ||
title: 'Quant' | ||
route_name: quant.config | ||
description: 'Configuration for the quant static exporter' | ||
parent: quant | ||
weight: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
use Drupal\Core\Render\RenderContext; | ||
use Drupal\Core\Routing\RouteMatch; | ||
use Drupal\Core\Session\AnonymousUserSession; | ||
use Drupal\quant\Event\NodeInsertEvent; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
function quant_node_insert(Drupal\Core\Entity\EntityInterface $entity) { | ||
// Dispatch the node insert demo event so that subscribers can act accordingly. | ||
\Drupal::service('event_dispatcher')->dispatch(NodeInsertEvent::NODE_INSERT_EVENT, new NodeInsertEvent($entity)); | ||
} | ||
|
||
function quant_node_update(Drupal\Core\Entity\EntityInterface $entity) { | ||
\Drupal::service('event_dispatcher')->dispatch(NodeInsertEvent::NODE_INSERT_EVENT, new NodeInsertEvent($entity)); | ||
} | ||
|
||
// function quant_node_load($entities) { | ||
// $entity = reset($entities); | ||
// \Drupal::service('event_dispatcher')->dispatch(NodeInsertEvent::NODE_INSERT_EVENT, new NodeInsertEvent($entity)); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
configure quant: | ||
title: 'Administer Quant configuration' | ||
restrict access: true | ||
bulk quant export: | ||
title: 'Trigger a bulk export/seed via Quant' | ||
restrict access: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
quant.config: | ||
path: '/admin/config/quant' | ||
defaults: | ||
_form: 'Drupal\quant\Form\ConfigForm' | ||
_title: 'Configure Quant' | ||
requirements: | ||
_permission: 'configure quant' | ||
|
||
quant.seed: | ||
path: '/admin/config/quant/seed' | ||
defaults: | ||
_form: 'Drupal\quant\Form\SeedForm' | ||
_title: 'Generate bulk export/seed of web content' | ||
requirements: | ||
_permission: 'bulk quant export' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
services: | ||
plugin.manager.quant.metadata: | ||
class: Drupal\quant\Plugin\QuantMetadataManager | ||
parent: default_plugin_manager | ||
|
||
quant.entity_renderer: | ||
class: Drupal\quant\EntityRenderer | ||
arguments: | ||
- '@config.factory' | ||
- '@entity.manager' | ||
- '@renderer' | ||
- '@main_content_renderer.html' | ||
- '@plugin.manager.display_variant' | ||
- '@theme.initialization' | ||
- '@theme.manager' | ||
- '@account_switcher' | ||
|
||
quant.node.insert: | ||
class: Drupal\quant\EventSubscriber\NodeInsertSubscriber | ||
arguments: | ||
- '@quant.entity_renderer' | ||
- '@plugin.manager.quant.metadata' | ||
tags: | ||
- { name: 'event_subscriber' } | ||
|
||
quant.output.filesystem: | ||
class: Drupal\quant\EventSubscriber\QuantFilesystem | ||
tags: | ||
- { name: 'event_subscriber' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Drupal\quant\Annotation; | ||
|
||
use Drupal\Component\Annotation\Plugin; | ||
|
||
/** | ||
* Defines the metadata item annotation object. | ||
* | ||
* @see \Drupal\quant\Plugin\MetadataInterface | ||
* @see plugin_api | ||
* | ||
* @Annotation | ||
*/ | ||
class Metadata extends Plugin { | ||
|
||
/** | ||
* The metadata id. | ||
* | ||
* @var string | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* The metadata label. | ||
* | ||
* @var string | ||
*/ | ||
public $label; | ||
|
||
} |
Oops, something went wrong.