The webform content creator is a great module and a real asset to the webform suite of modules, the issue I see is that at the moment field support is limited to just what the module provides where it feels like this could be easily opened up to make use of the plugin system.

I realised this as I was trying to add a patch to enable the mapped value to be adapted, in my case to allow address fields to be utilised.

I suspect the best approach would be to add a ContentCreatorSourceMap plugin, which would be selectable when mapping the field, with just a few attributes

* label
* [webform_element_types]

and would just have a mapValue() method.

By default you could just have an EntityReferenceContentCreatorSourceMap, CheckboxContentCreatorSourceMap, DefaultContentCreatorSourceMap which would just allow the logic in the entity mapNodeField method to be largely abstracted away. And could then be easily extended for other element types.

If I get time I'll try to take a bit more of a look at this, if it's something you think makes sense.

Comments

andy_w created an issue. See original summary.

andy_w’s picture

andy_w’s picture

Status: Needs work » Needs review

So I made use of this hook to make address fields (from the loqate module) work, but could then be utilised for all sorts of complex field support

/**
 * Implements hook_webform_content_creator_field_map_value_alter().
 */
function mymodule_webform_content_creator_field_map_value_alter(&$value, $data) {
  if ($data['source_type'] === 'webform_address_loqate') {
    $fields_to_remap = [
      'country' => 'country_code',
      'address' => 'address_line1',
      'address_2' => 'address_line2',
      'city' => 'locality',
      'region' => 'administrative_area',
    ];
    foreach ($fields_to_remap as $old_field => $new_field) {
      if (!isset($value[$old_field])) {
        continue;
      }
      $value[$new_field] = $value[$old_field];
      unset($value[$old_field]);
    }
  }
}
joaomarques736’s picture

Hi andy_w,

This would be an excellent feature and really makes sense! The mapNodeField method should only have the basic logic related to it, and for the complex fields we could have a plugin to extend it, as you say. Can you help me on this?

Best regards and thank you for your hard work!

andy_w’s picture

I can try to take a look :)

andy_w’s picture

I've added a very early pass at a source map type plugin and manager, this is still conceptual at this stage. I think the next step would be to add some functional tests to be able to continue this with confidence if we think the direction has potential / value.

jacobbell84’s picture

Hi @andy_w,
I came to the same conclusion in this thread (https://www.drupal.org/project/webform_content_creator/issues/3058868) and had begun to work on a plugin system a little while back. Maybe we join forces on this? I like the the approach in yours allowing the user to choose which plugin to use. In mine, I have all the core functionality reworked in plugins, along with some more advanced features like being able to map basic fields to more complex field types (in case there isn't a perfect match for the field in webforms). I think we could take the best of both patches and come up with a pretty comprehensive solution.

joaomarques736’s picture

Hello andy_w and jacobbell84,

This idea of a new plugin system is excellent and i would say exactly the same: the idea is the same but the implementation is a little bit different, so it would be nice to get the best of both approaches and i would like to apply this in a new release (2.0.0). It would improve scalability and it would be easier to add support for complex fields (images, datetimes, links, dynamic entity references ..) and in an organized way.

Best regards and thank you for your contribution!

jacobbell84’s picture

@joaomarques736 Excellent, that's great to hear! Thank you for for all the work you've done on this module, I've used it a on a few projects already.

dgaspara’s picture

jacobbell84’s picture

styrbaek’s picture

Could anyone help creating this patch for version 2.x?

pcate’s picture

I'm very excited about this new plugin system. It will add support the several additional fields types that's currently preventing me from using the module for a project.

I am a bit confused about which issue the development of the plugin system is being done in though. There has been work in this issue, but also in https://www.drupal.org/project/webform_content_creator/issues/3058868 and there are separate several issues for adding new field types that I think will be addressed with the new plugin system. Do we need to consolidate these issues, or at least create a meta issue?

Also, it looks like the new plugin system will be in v3 release of the module? Is there an ETA when we might be a version 3 alpha?

joaomarques736’s picture

Version: 8.x-1.x-dev » 3.0.0-alpha2
joaomarques736’s picture

Hello andy_w and jacobbell84,

Thanks for your great contribution with the new plugin system, I tried to join some things of each patch to make a release (3.0.0-alpha) with this plugin system, which will allow any person to extend the module and map any field types.

Best regards!

joaomarques736’s picture

Status: Needs review » Fixed
joaomarques736’s picture

Status: Fixed » Closed (fixed)