Closed (fixed)
Project:
Payment
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Jan 2013 at 09:42 UTC
Updated:
21 Jan 2014 at 17:10 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
xanoWe may want to rename contexts to "payment types", and create different classes for the different types. A payment that is of the base class is a payment without a type. We can let payment types be exposed plugin classes, and use a custom payment entity storage controller to decide which entity class to use. We can use the plugins' machine names as bundle names.
Perhaps we can even allow payment type plugins to set a custom storage controller as well, to make it easier for payment types to provide CRUD operations, something which at the moment needs to be done by implementing entity event hooks, such as hook_payment_insert().
Comment #2
xanoComment #3
xanoSimply use context plugin IDs as payment bundles so contexts can use configurable fields to storage data.
Comment #4
xanoRequired for #2047805: Port the payment form field.
Comment #5
pbuyle commentedRegarding having different classes for different bundles, the Entity bundle plugin module provides support for a per-bundle classes through (CTools) plugin (for Drupal 7). The idea is interesting, but there is really no need for a complex solution involving a heavily customized entity controller. The Strategy Pattern (https://en.wikipedia.org/wiki/Strategy_pattern) fits the need for per-bundle behavior perfectly (if any): a Payment is the Context and its bundle the Concrete strategy.
Comment #6
xanoCurrently payments have a context plugin which defines the payment type. This will be expanded by adding a computed property that points to the plugin ID as the bundle, and by exposing context plugins as payment bundles. All context-related logic will remain in the plugin, but contexts can then add fields to payments to store their data in. This approach solves most issues that have arisen so far, and it does not deviate from how core does things, except for the computed bundle property, but that should be harmless.
Comment #7
pbuyle commentedThat sounds great.
Comment #8
xanoThing is, I need to find out the best way to implement this. Other systems may expect to be able to set the bundle on a payment by passing on a string to the bundle field. The actual bundle is defined by the payment's context plugin. I'm not sure whether to use a computed field for the bundle, or whether to store the bundle and plugin side by side and tell people not to touch them.
Comment #9
pbuyle commentedYou could prevent edition of the context/bundle property by implementing it through
__get()on the Payment class.You could also implement the bundle property assignation through
__set()on the Payment class.Comment #10
xanoWe can't just do that directly. The property needs to be an entity field. See https://drupal.org/node/1806650 if you're not familiar with the new entity field API and typed data API yet.
Comment #11
xanoEntity NG only needs to set the bundle upon entity creation/instantiation. For payments this means that the context plugin ID is passed on on creation, and that the storage controller creates a plugin instance using that and sets it on the payment. PaymentInterface::bundle() can then return the plugin instance's pluginId() return value.
Comment #12
xanoComment #13
xano