Consider converting payment types to typed data, so we can set them on payments as base fields, and modules like Rules can possibly 'browse' the data/configuration on the plugins.

Comments

xano’s picture

Title: Convet payment type plugins to typed data » Convert payment type plugins to typed data
xano’s picture

Status: Active » Postponed
Related issues: +#2294745: Add a field type for plugins
xano’s picture

Consider adding an interface and a trait for plugins to implements, so they can notify the field of changes and both can be kept in sync with each other.

xano’s picture

Title: Convert payment type plugins to typed data » Convert plugins on payment entities to fields
Status: Postponed » Needs review
StatusFileSize
new23.78 KB

This patch introduces the field types, but does not yet convert the plugins on payments to fields, nor does it remove current storage code.

xano’s picture

StatusFileSize
new25.2 KB
xano’s picture

StatusFileSize
new43.48 KB
new57.14 KB

Status: Needs review » Needs work

The last submitted patch, 6: payment_2134761_6.patch, failed testing.

xano’s picture

StatusFileSize
new36.75 KB
new78.79 KB

onChange() turns out to be *extremely* unreliable for doing anything, as setValue()'s documentation implies the $notify parameter should be FALSE mostly/only when setting a child property's value from a parent. However, TypedDataManager sets $notify to FALSE for no documented reason.

To work around this, I think the only option is to create special data types for each of the field's properties so we can explicitly notify the field (which is the parent) when a property's value changes and as such reliably synchronize all properties.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new39.61 KB
new90.28 KB

Seeing as we had to enforce a plugin instance to exist for every field item at all times anyway, it's probably better if the plugin ID and plugin configuration properties are converted to computed properties that are only used for storage, because removes the need for synchronization between the plugin instance and the field item and between the field item's properties.

xano’s picture

StatusFileSize
new63.43 KB

This is with computed properties. As I should have expected, this won't work without entity storage modifications, because the storage cannot set the values for the computed properties. Just storing a serialized plugin could work, but if we want to be able to query the field, we'll have to store the plugin ID as well.

xano’s picture

We can't serialize the entire instance, because it's an instance of a plugin class and plugins by nature are not always available.

xano’s picture

StatusFileSize
new76.94 KB

Let's try a slightly different approach: three field item properties, of which two proxy calls to the instance that must always exist as the value of the third property. Proxying prevent synchronization problems, while always having an instance (unless the item has no value) keeps the code simple enough to maintain.

Patch is not ready and some tests still fail.

The last submitted patch, 9: payment_2134761_9.patch, failed testing.

The last submitted patch, 10: payment_2134761_10.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 12: payment_2134761_12.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new77.21 KB

Re-roll.

Status: Needs review » Needs work

The last submitted patch, 16: payment_2134761_16.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new80.81 KB
new12.25 KB

Status: Needs review » Needs work

The last submitted patch, 18: payment_2134761_18.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new102.06 KB
new28.34 KB

Many plugins are payment-aware. However, now they no longer have to be set through the payment entity, but can also be set through field API. A simple onChange() on payment entities did not work, because TypedDataManager created field items and sets their values before they are set on the parent. This means the parent (the payment) is notified, wants to grab the instance from the field, but at that point the field is not assigned to the parent yet (one-way reference) and we end up in an infinite loop. Enter PaymentAwarePluginBagItemBase. It doesn't seem to solve all problems yet.

*Puts on his thinking cap*

Status: Needs review » Needs work

The last submitted patch, 20: payment_2134761_20.patch, failed testing.

xano’s picture

This needs a modification to FieldItemBase:

diff --git a/core/lib/Drupal/Core/Field/FieldItemBase.php b/core/lib/Drupal/Core/Field/FieldItemBase.php
index b411b88..2ae8f94 100644
--- a/core/lib/Drupal/Core/Field/FieldItemBase.php
+++ b/core/lib/Drupal/Core/Field/FieldItemBase.php
@@ -142,8 +142,8 @@ protected function writePropertyValue($property_name, $value) {
   public function __get($name) {
     // There is either a property object or a plain value - possibly for a
     // not-defined property. If we have a plain value, directly return it.
-    if (isset($this->properties[$name])) {
-      return $this->properties[$name]->getValue();
+    if (array_key_exists($name, $this->getPropertyDefinitions())) {
+      return $this->get($name)->getValue();
     }
     elseif (isset($this->values[$name])) {
       return $this->values[$name];

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new102.48 KB

This includes the fix from #22 added to PluginBagItemBase.

Status: Needs review » Needs work

The last submitted patch, 23: payment_2134761_23.patch, failed testing.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new7.78 KB
new101.24 KB
xano’s picture

Status: Needs review » Fixed

  • Xano committed 33e922c on 8.x-2.x
    Issue #2134761 by Xano: Added Convert plugins on payment entities to...

  • Xano committed 2a527ec on 8.x-2.x
    Issue #2134761 by Xano: Added Convert plugins on payment entities to...
  • Xano committed 7799294 on 8.x-2.x
    Issue #2134761 by Xano: Added Convert plugins on payment entities to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.