【问题标题】:Drupal 8 - Submit Webform to an external APIDrupal 8 - 将 Web 表单提交到外部 API
【发布时间】:2020-06-29 05:55:15
【问题描述】:

我的 Drupal 网站 (8.8.5) 上有一个 Web 表单。 Webform 有多个字段以及两个文件字段。

当用户提交 Web 表单时,我想将详细信息发送到外部 API (SugarCRM),包括 Web 表单中附加的文件。

我该怎么做? Drupal 8 中是否有可用的模块来轻松实现这一点?还是需要我手动处理提交的数据并调用API?

我还想将数据存储在网站上,因为它通常可以正常工作。

【问题讨论】:

    标签: api drupal drupal-8


    【解决方案1】:

    我相信Webform SugarCRM Integration 可能正是您所追求的。它有一个用于 Drupal 8 的稳定版本 8.x-2.1

    如果它不符合您的需要,您可以编写自己的自定义 Web 表单处理程序。如下所示,扩展了 Webform 的 WebformHandlerBase 类:

    <?php
    
    namespace Drupal\your_module\Plugin\WebformHandler;
    
    use Drupal\webform\Plugin\WebformHandlerBase;
    
    /**
     * Class SugarCrmWebformHandler.
     *
     * @package Drupal\your_module\Plugin\WebformHandler
     *
     * @WebformHandler(
     *   id = "sugar_crm",
     *   label = @Translation("Sugar CRM"),
     *   category = @Translation("External"),
     *   description = @Translation("Webform handler integrating with Sugar CRM."),
     *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
     *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
     * )
     */
    class SugarCrmWebformHandler extends WebformHandlerBase {
    
      /**
       * {@inheritdoc}
       */
      public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
        # code for Sugar CRM...
      }
    
    }
    

    或者,您也可以考虑使用 Webform 的 RemotePostWebformHandler 类,它可以为您的集成提供一些样板。

    查看其他资源:

    【讨论】:

    • 太棒了。这在所有其他领域都表现良好。但是,您知道如何将文件从 Drupal 网站上传到 SugarCRM。
    猜你喜欢
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    相关资源
    最近更新 更多