Skip to content

Commit

Permalink
Initial scaffolding commit #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazanir committed Sep 28, 2017
1 parent 056e389 commit 0c384d3
Show file tree
Hide file tree
Showing 24 changed files with 1,015 additions and 16 deletions.
6 changes: 6 additions & 0 deletions commerce_recurring.links.action.yml
@@ -0,0 +1,6 @@
entity.commerce_recurring_engine.add_form:
route_name: entity.commerce_recurring_engine.add_form
title: 'Add recurring engine'
appears_on:
- entity.commerce_recurring_engine.collection

12 changes: 12 additions & 0 deletions commerce_recurring.links.menu.yml
@@ -0,0 +1,12 @@
commerce_recurring.configuration:
title: 'Recurring'
route_name: 'commerce_recurring.configuration'
parent: 'commerce.configuration'
weight: -10

entity.commerce_recurring_engine.collection:
title: 'Recurring engines'
route_name: 'entity.commerce_recurring_engine.collection'
parent: 'commerce_recurring.configuration'
description: 'Configure the recurring engines that manage recurring orders and subscriptions.'

8 changes: 8 additions & 0 deletions commerce_recurring.links.task.yml
@@ -0,0 +1,8 @@
# @TODO: Subscriptions collections/canonical?
#

entity.commerce_recurring_engine.edit_form:
route_name: entity.commerce_recurring_engine.edit_form
base_route: entity.commerce_recurring_engine.edit_form
title: Edit

4 changes: 4 additions & 0 deletions commerce_recurring.permissions.yml
@@ -0,0 +1,4 @@
administer commerce_recurring_engine:
title: 'Administer recurring engines'
'restrict access': TRUE

17 changes: 17 additions & 0 deletions commerce_recurring.plugin_type.yml
@@ -0,0 +1,17 @@
commerce_recurring.recurring_engine:
label: Commerce recurring engine
provider: commerce_recurring
plugin_manager_service_id: plugin.manager.commerce_recurring_engine
plugin_definition_decorator_class: Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator

commerce_recurring.subscription_type:
label: Commerce subscription type
provider: commerce_recurring
plugin_manager_service_id: plugin.manager.commerce_subscription_type
plugin_definition_decorator_class: Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator

commerce_recurring.usage_type:
label: Commerce usage type
provider: commerce_recurring
plugin_manager_service_id: plugin.manager.commerce_usage_type
plugin_definition_decorator_class: Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator
File renamed without changes.
13 changes: 10 additions & 3 deletions commerce_recurring.services.yml
Expand Up @@ -2,10 +2,17 @@ services:
plugin.manager.commerce_subscription_type:
class: Drupal\commerce_recurring\SubscriptionTypeManager
parent: default_plugin_manager

plugin.manager.commerce_recurring_engine:
class: Drupal\commerce_recurring\RecurringEngineManager
parent: default_plugin_manager
plugin.manager.commerce_recurring_usage_group:
class: Drupal\commerce_recurring\RecurringUsageGroupManager
parent: default_plugin_manager

plugin.manager.commerce_usage_type:
class: Drupal\commerce_recurring\UsageTypeManager
parent: default_plugin_manager

commerce_recurring.storage.usage_record:
class: Drupal\commerce_recurring\UsageRecordDatabaseStorage
arguments: ['@database']
tags:
- { name: backend_overridable }
Expand Up @@ -5,15 +5,15 @@
use Drupal\Component\Annotation\Plugin;

/**
* Defines the recurring engine plugin annotation object.
* Defines the usage type plugin annotation object.
*
* Plugin namespace: Plugin\Commerce\RecurringEngine.
* Plugin namespace: Plugin\Commerce\UsageType.
*
* @see plugin_api
*
* @Annotation
*/
class CommerceRecurringUsageGroup extends Plugin {
class CommerceRecurringUsageType extends Plugin {

/**
* The plugin ID.
Expand All @@ -23,7 +23,7 @@ class CommerceRecurringUsageGroup extends Plugin {
public $id;

/**
* The usage group label.
* The usage type label.
*
* @ingroup plugin_translatable
*
Expand Down
199 changes: 199 additions & 0 deletions src/Entity/RecurringEngine.php
@@ -0,0 +1,199 @@
<?php

namespace Drupal\commerce_recurring\Entity;

use Drupal\commmerce\CommerceSinglePluginCollection;
use Drupal\Core\Config\Entity\ConfigEntityBase;

/**
* Defines the recurring engine entity class.
*
* @ConfigEntityType(
* id = "commerce_recurring_engine",
* label = @Translation("Recurring engine"),
* label_collection = @Translation("Recurring engines"),
* label_singular = @Translation("recurring engine"),
* label_plural = @Translation("recurring engines"),
* label_count = @PluralTranslation(
* singular = "@countrecurring engines",
* plural = "@count recurring engines",
* ),
* handlers = {
* "list_builder" = "Drupal\commerce_recurring\RecurringEngineListBuilder",
* "storage" = "Drupal\commerce_recurring\RecurringEngineStorage",
* "form" = {
* "add" = "Drupal\commerce_recurring\Form\RecurringEngineForm",
* "edit" = "Drupal\commerce_recurring\Form\RecurringEngineForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm"
* },
* "route_provider" = {
* "default" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
* },
* },
* admin_permission = "administer commerce_recurring_engine",
* config_prefix = "commerce_recurring_engine",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid",
* "weight" = "weight",
* "status" = "status",
* },
* config_export = {
* "id",
* "label",
* "weight",
* "status",
* "plugin",
* "configuration",
* },
* links = {
* "add-form" = "/admin/commerce/config/recurring-engines/add",
* "edit-form" = "/admin/commerce/config/recurring-engines/manage/{commerce_recurring_engine}",
* "delete-form" = "/admin/commerce/config/recurring-engines/manage/{commerce_recurring_engine}/delete",
* "collection" = "/admin/commerce/config/recurring-engines"
* }
* )
*/
class RecurringEngine extends ConfigEntityBase implements RecurringEngineInterface {

/**
* The recurring engine ID.
*
* @var string
*/
protected $id;

/**
* The recurring engine label.
*
* @var string
*/
protected $label;

/**
* The recurring engine weight.
*
* @var int
*/
protected $weight;

/**
* The plugin ID.
*
* @var string
*/
protected $plugin;

/**
* The plugin configuration.
*
* @var array
*/
protected $configuration = [];

/**
* The plugin collection that holds the recurring engine plugin.
*
* @var \Drupal\commerce\CommerceSinglePluginCollection
*/
protected $pluginCollection;

/**
* {@inheritdoc}
*/
public function getWeight() {
return $this->weight;
}

/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
return $weight;
}

/**
* {@inheritdoc}
*/
public function getPlugin() {
return $this->getPluginCollection()->get($this->plugin);
}

/**
* {@inheritdoc}
*/
public function getPluginId() {
return $this->plugin;
}

/**
* {@inheritdoc}
*/
public function setPluginId($plugin_id) {
$this->plugin = $plugin_id;
$this->configuration = [];
$this->pluginCollection = NULL;
return $this;
}

/**
* {@inheritdoc}
*/
public function getPluginConfiguration() {
return $this->configuration;
}

/**
* {@inheritdoc}
*/
public function setPluginConfiguration(array $configuration) {
$this->configuration = $configuration;
$this->pluginCollection = NULL;
return $this;
}

/**
* {@inheritdoc}
*/
public function getPluginCollections() {
return [
'configuration' => $this->getPluginCollection(),
];
}

/**
* {@inheritdoc}
*/
public function set($property_name, $value) {
// Invoke the setters to clear related properties.
if ($property_name == 'plugin') {
$this->setPluginId($value);
}
elseif ($property_name == 'configuration') {
$this->setPluginConfiguration($value);
}
else {
return parent::set($property_name, $value);
}
}

/**
* Gets the plugin collection that holds the recurring engine plugin.
*
* Ensures the plugin collection is initialized before returning it.
*
* @return \Drupal\commerce\CommerceSinglePluginCollection
* The plugin collection.
*/
protected function getPluginCollection() {
if (!$this->pluginCollection) {
$plugin_manager = \Drupal::service('plugin.manager.commerce_recurring_engine');
$this->pluginCollection = new CommerceSinglePluginCollection($plugin_manager, $this->plugin, $this->configuration, $this->id);
}
return $this->pluginCollection;
}

}

84 changes: 84 additions & 0 deletions src/Entity/RecurringEngineInterface.php
@@ -0,0 +1,84 @@
<?php


namespace Drupal\commerce_recurring\Entity;

use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;

/**
* Defines the interface for recurring engine configuration entities.
*
* Stores configuration for recurring engine plugins.
*/
interface RecurringEngineInterface extends ConfigEntityInterface, EntityWithPluginCollectionInterface {

/**
* Gets the recurring engine weight.
*
* @return string
* The recurring engine weight.
*/
public function getWeight();

/**
* Sets the recurring engine weight.
*
* @param int $weight
* The recurring engine weight.
*
* @return $this
*/
public function setWeight($weight);

/**
* Gets the recurring engine plugin.
*
* @return \Drupal\commerce_recurring\Plugin\Commerce\RecurringEngine\RecurringEngineInterface
* The recurring engine plugin.
*/
public function getPlugin();

/**
* Gets the recurring engine plugin ID.
*
* @return string
* The recurring engine plugin ID.
*/
public function getPluginId();

/**
* Sets the recurring engine plugin ID.
*
* @param string $plugin_id
* The recurring engine plugin ID.
*
* @return $this
*/
public function setPluginId($plugin_id);

/**
* Gets the recurring engine plugin configuration.
*
* @return string
* The recurring engine plugin configuration.
*/
public function getPluginConfiguration();

/**
* Sets the recurring engine plugin configuration.
*
* @param array $configuration
* The recurring engine plugin configuration.
*
* @return $this
*/
public function setPluginConfiguration(array $configuration);

// @TODO: Figure out what other methods (from the plugin?) we might
// want to have on the config entity itself, probably for the sake
// of convenience? Not sure why gateways wrap those functions exactly.

}

0 comments on commit 0c384d3

Please sign in to comment.