Skip to content

Commit

Permalink
Repository cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
stooit committed Mar 9, 2020
0 parents commit 8af1b3c
Show file tree
Hide file tree
Showing 33 changed files with 1,493 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/install/quant.settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
content_revisions: TRUE
asset_revisions: TRUE
storage_location: ../html
9 changes: 9 additions & 0 deletions modules/quant_api/quant_api.info.yml
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
6 changes: 6 additions & 0 deletions modules/quant_api/quant_api.links.menu.yml
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
9 changes: 9 additions & 0 deletions modules/quant_api/quant_api.routing.yml
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
13 changes: 13 additions & 0 deletions modules/quant_api/quant_api.services.yml
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' }
34 changes: 34 additions & 0 deletions modules/quant_api/src/Client/QuantClient.php
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;
}

}
33 changes: 33 additions & 0 deletions modules/quant_api/src/Client/QuantClientInterface.php
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;

}
52 changes: 52 additions & 0 deletions modules/quant_api/src/EventSubscriber/QuantApi.php
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) {

}

}
80 changes: 80 additions & 0 deletions modules/quant_api/src/Form/SettingsForm.php
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);
}

}
6 changes: 6 additions & 0 deletions quant.info.yml
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
13 changes: 13 additions & 0 deletions quant.links.menu.yml
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
22 changes: 22 additions & 0 deletions quant.module
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));
// }
6 changes: 6 additions & 0 deletions quant.permissions.yml
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
15 changes: 15 additions & 0 deletions quant.routing.yml
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'
29 changes: 29 additions & 0 deletions quant.services.yml
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' }
31 changes: 31 additions & 0 deletions src/Annotation/Metadata.php
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;

}
Loading

0 comments on commit 8af1b3c

Please sign in to comment.