Problem/Motivation

A custom migration might need a lot of very small custom process plugins for their properties. This results in an astonishing amount of boilerplate as most process plugins are 1-5 lines of code with 30+ lines of boilerplate.

Proposed resolution

Make it possible to call any method in a process plugin. As a demo, convert the two skip on empty plugins into one.

Remaining tasks

Document this in the handbook.

User interface changes

API changes

Minimal. If you used these two plugins then run sed -i -f 2509496_sed.txt * in the directory where your configs are and you are set.

Data model changes

Do we need to write an upgrade hook for migrate? I am wondering. If we need to, of course I can.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, flex.patch, failed testing.

chx’s picture

Status: Needs work » Needs review
FileSize
8.76 KB

Status: Needs review » Needs work

The last submitted patch, 2: 2509496_2.patch, failed testing.

chx’s picture

Issue summary: View changes
FileSize
12.18 KB
chx’s picture

FileSize
11.36 KB
chx’s picture

Status: Needs work » Needs review
FileSize
11.36 KB

Typofix

benjy’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I've reviewed this a couple of times today and we discussed the approach on IRC. I think this is a nice pattern and a good simplification of the skip process plugins.

chx’s picture

Issue summary: View changes
FileSize
158 bytes
phenaproxima’s picture

Status: Reviewed & tested by the community » Needs work

I'm ambivalent about having configuration specify which method to call, but OTOH I'm all for reducing boilerplate. So +1 for this.

However...

+++ b/core/modules/migrate/src/ProcessPluginBase.php
+  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+    // Do not call this method from children.
+    if (isset($this->configuration['method'])) {
+      return $this->{$this->configuration['method']}($value, $migrate_executable, $row, $destination_property);
+    }
+    throw new \BadMethodCallException();

The exception should include a message.

+++ b/core/modules/migrate/src/Plugin/migrate/process/SkipOnEmpty.php
+   * Skip the rest of the processing on 0.
+   */
+  public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+    if (!$value) {
+      throw new MigrateSkipProcessException();
+    }

The doc comment is misleading. It skips the processing if the value is falsy/empty, not just 0.

+++ b/core/modules/migrate/src/ProcessPluginBase.php
+  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+    // Do not call this method from children.
+    if (isset($this->configuration['method'])) {

There is no check that the method actually exists and is callable. Should there be a bit of validation here, and an exception thrown if $configuration['method'] is invalid? To that end, isset() should probably be !empty().

chx’s picture

Status: Needs work » Needs review
FileSize
1.77 KB
12.24 KB

The last submitted patch, flex.patch, failed testing.

The last submitted patch, 2: 2509496_2.patch, failed testing.

benjy’s picture

Can we add the non-existent method name to the exception message?

chx’s picture

FileSize
1.34 KB
12.44 KB
benjy’s picture

Status: Needs review » Reviewed & tested by the community

Great!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Migrate is not subject beta evaluations. Committed 8d3755c and pushed to 8.0.x. Thanks!

  • alexpott committed 8d3755c on 8.0.x
    Issue #2509496 by chx, benjy, phenaproxima: Make migrate process plugins...

Status: Fixed » Closed (fixed)

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