From c0f70f418e2123a8b13173a10857b23e42fe5b89 Mon Sep 17 00:00:00 2001
From: Jaap Jansma <jaap@edeveloper.nl>
Date: Thu, 15 Feb 2018 16:49:36 +0100
Subject: [PATCH] added a api provider for the form processor.

---
 CRM/FormProcessor/BAO/FormProcessor.php |  2 +-
 Civi/FormProcessor/API/Provider.php     | 58 +++++++++++++++++++++++++
 api/v3/FormProcessor/Delete.php         |  4 +-
 form_processor.php                      | 13 ++++++
 info.xml                                |  3 ++
 5 files changed, 78 insertions(+), 2 deletions(-)
 create mode 100644 Civi/FormProcessor/API/Provider.php

diff --git a/CRM/FormProcessor/BAO/FormProcessor.php b/CRM/FormProcessor/BAO/FormProcessor.php
index 1d365ed..99f65d0 100644
--- a/CRM/FormProcessor/BAO/FormProcessor.php
+++ b/CRM/FormProcessor/BAO/FormProcessor.php
@@ -95,7 +95,7 @@
 
     CRM_Utils_Hook::pre('delete', 'FormProcessor', $id, CRM_Core_DAO::$_nullArray);
 
-    $rule = new FormProcessor();
+    $rule = new CRM_FormProcessor_BAO_FormProcessor();
     $rule->id = $id;
     $rule->delete();
 
diff --git a/Civi/FormProcessor/API/Provider.php b/Civi/FormProcessor/API/Provider.php
new file mode 100644
index 0000000..77f6f76
--- /dev/null
+++ b/Civi/FormProcessor/API/Provider.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
+ * @license http://www.gnu.org/licenses/agpl-3.0.html
+ */
+ 
+ namespace Civi\FormProcessor\API;
+ 
+ use \Civi\API\Provider\ProviderInterface as API_ProviderInterface;
+
+ 
+ class Provider implements API_ProviderInterface {
+ 	
+	public function __construct() {
+		
+	}
+ 	
+	/**
+   * @param array $apiRequest
+   *   The full description of the API request.
+   * @return array
+   *   structured response data (per civicrm_api3_create_success)
+   * @see civicrm_api3_create_success
+   * @throws \API_Exception
+   */
+  public function invoke($apiRequest) {
+  	// Run the api
+  }
+
+  /**
+   * @param int $version
+   *   API version.
+   * @return array<string>
+   */
+  public function getEntityNames($version) {
+  	return array(
+  		'FormProcessorExecuter'
+		);
+  }
+
+  /**
+   * @param int $version
+   *   API version.
+   * @param string $entity
+   *   API entity.
+   * @return array<string>
+   */
+  public function getActionNames($version, $entity) {		
+  	$params['is_active'] = 1;
+  	$form_processors = \CRM_FormProcessor_BAO_FormProcessor::getValues($params);
+		$actions = array();
+		foreach($form_processors as $form_processor) {
+			$actions[] = $form_processor['name'];
+		}
+		return $actions;
+  }
+	
+ }
diff --git a/api/v3/FormProcessor/Delete.php b/api/v3/FormProcessor/Delete.php
index 0bfeb6d..f509d48 100644
--- a/api/v3/FormProcessor/Delete.php
+++ b/api/v3/FormProcessor/Delete.php
@@ -1,5 +1,7 @@
 <?php
 
+use CRM_FormProcessor_ExtensionUtil as E;
+
 /**
  * CiviRuleRule.Delete API specification (optional)
  * This is used for documentation and validation.
@@ -29,7 +31,7 @@ function civicrm_api3_form_processor_Delete($params) {
   if (!array_key_exists('id', $params) || empty($params['id'])) {
     throw new API_Exception('Parameter id is mandatory and can not be empty in ' . __METHOD__, 0010);
   } else {
-    return civicrm_api3_create_success(CRM_Civirules_BAO_Rule::deleteWithId($params['id']), $params, 'CiviRuleRule', 'Delete');
+    return civicrm_api3_create_success(CRM_FormProcessor_BAO_FormProcessor::deleteWithId($params['id']), $params, 'FormProcessor', 'Delete');
   }
 }
 
diff --git a/form_processor.php b/form_processor.php
index 2623c7e..8d0398a 100644
--- a/form_processor.php
+++ b/form_processor.php
@@ -3,6 +3,19 @@
 require_once 'form_processor.civix.php';
 use CRM_FormProcessor_ExtensionUtil as E;
 
+function form_processor_civicrm_container($container) {
+	// Register our API Provider.
+	// The API provider is used to process incoming api calls and process them
+	// with the form processor logic.	
+	
+	$apiProviderDefinition = new \Symfony\Component\DependencyInjection\Definition('Civi\FormProcessor\API\Provider');
+	$apiKernelDefinition = $container->getDefinition('civi_api_kernel');
+	$apiKernelDefinition->addMethodCall('registerApiProvider', array($apiProviderDefinition)); 
+}
+
+/**
+ * Check whether the action provider extension is installed and enabled.
+ */
 function _formprocessor_is_action_provider_installed() {
   $installed = FALSE;
   try {
diff --git a/info.xml b/info.xml
index b526c6a..0c726a6 100644
--- a/info.xml
+++ b/info.xml
@@ -20,6 +20,9 @@
     <ver>4.7</ver>
   </compatibility>
   <comments>This is a module in prototype stage</comments>
+  <classloader>
+    <psr4 prefix="Civi\" path="Civi" />
+	</classloader>
   <civix>
     <namespace>CRM/FormProcessor</namespace>
   </civix>
-- 
GitLab