Skip to content
Snippets Groups Projects
form_processor.php 8.88 KiB
Newer Older
  • Learn to ignore specific revisions
  • jaapjansma's avatar
    jaapjansma committed
    <?php
    
    require_once 'form_processor.civix.php';
    use CRM_FormProcessor_ExtensionUtil as E;
    
    
    use \Symfony\Component\DependencyInjection\ContainerBuilder;
    use \Symfony\Component\DependencyInjection\Definition;
    
    /**
     * Implements hook_civicrm_container()
     *
     * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_container/
     */
    function form_processor_civicrm_container(ContainerBuilder $container) {
    	// Register the TypeFactory
    	$container->setDefinition('form_processor_type_factory', new Definition('Civi\FormProcessor\Type\Factory'));
    	
    	
    
    	// Register our API Provider.
    	// The API provider is used to process incoming api calls and process them
    	// with the form processor logic.	
    
    	$apiProviderDefinition = new Definition('Civi\FormProcessor\API\Provider');
    
    	$apiKernelDefinition = $container->getDefinition('civi_api_kernel');
    	$apiKernelDefinition->addMethodCall('registerApiProvider', array($apiProviderDefinition)); 
    }
    
    
    /**
     * Implements hook_civicrm_alterAPIPermissions()
     * 
     * All Form Processor api's are under the Administer CiviCRM permission.
     * Except for the FormProcessorExecutor api.
     * 
     * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterAPIPermissions/
     */
    function form_processor_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) {
    		$permissions['form_processor']['get'] = array('administer CiviCRM');
    		$permissions['form_processor']['create'] = array('administer CiviCRM');
    		$permissions['form_processor']['delete'] = array('administer CiviCRM');
    		
    		$permissions['form_processor_input']['get'] = array('administer CiviCRM');
    		$permissions['form_processor_input']['create'] = array('administer CiviCRM');
    		$permissions['form_processor_input']['delete'] = array('administer CiviCRM');
    		
    		$permissions['form_processor_delete']['get'] = array('administer CiviCRM');
    		$permissions['form_processor_delete']['create'] = array('administer CiviCRM');
    		$permissions['form_processor_delete']['delete'] = array('administer CiviCRM');
    }
    
    
    /**
     * Check whether the action provider extension is installed and enabled.
     */
    
    function _formprocessor_is_action_provider_installed() {
      $installed = FALSE;
      try {
        $extensions = civicrm_api3('Extension', 'get', array('options' => array('limit' => 0)));
        foreach($extensions['values'] as $ext) {
          if ($ext['key'] == 'action-provider' && $ext['status'] == 'installed') {
            $installed = TRUE;
          }
        }
        return $installed;
      }
      catch (Exception $e) {
        return FALSE;
      }
      return FALSE;
    }
    
    
    /**
     * Implementation of hook_civicrm_pageRun
     *
     * Handler for pageRun hook.
     */
    function form_processor_civicrm_pageRun(&$page) {
      $f = '_' . __FUNCTION__ . '_' . get_class($page);
      if (function_exists($f)) {
        $f($page);
      }
    }
    
    function _form_processor_civicrm_pageRun_CRM_Admin_Page_Extensions(&$page) {
      _form_processor_prereqCheck();
    }
    
    function _form_processor_prereqCheck() {
      $unmet = CRM_FormProcessor_Upgrader::checkExtensionDependencies();
      CRM_FormProcessor_Upgrader::displayDependencyErrors($unmet);
    }
    
    
    function form_processor_get_action_provider() {
    	$action_provider_container = \Civi::service('action_provider');
    	return $action_provider_container->getProviderByContext('form_processor');
    }
    
    function form_processor_get_action_types() {
    	$provider = form_processor_get_action_provider();
    	return $provider->getActions();
    }
    
    
    /**
     * Implementation of hook_civicrm_navigationMenu.
     *
     * Adds Automation navigation items just before the Administer menu.
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu
     */
    function form_processor_civicrm_navigationMenu(&$params) {
      // get the Administer menu ID and position in the $params array
      $administerMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Navigation', 'Administer', 'id', 'name');
      $posOfAdminMenu = array_search($administerMenuId, array_keys($params)); 
    	
      $newNavId = _form_processor_getMenuKeyMax($params);
      $formProcessorMenu = array(
        $newNavId => array(
          'attributes' => array(
            'label' => ts('Automation'),
            'name' => 'automation',
            'url' => NULL,
            'permission' => 'administer CiviCRM',
            'operator' => NULL,
            'separator' => 0,
            'parentID' => NULL,
            'navID' => $newNavId,
            'active' => 1,
          ),
          'child' => array(
            $newNavId + 1 => array(
              'attributes' => array(
                'label' => E::ts('Form processors,'),
                'name' => 'form_processors',
                'url' => 'civicrm/admin/automation/formprocessor/#/formprocessors',
                'permission' => 'administer CiviCRM',
                'operator' => NULL,
                'separator' => 0,
                'parentID' => $newNavId,
                'navID' => $newNavId + 1,
                'active' => 1,
              ),
              'child' => array(),
            ),
          ),
        ),
      );
    
      // insert volunteer menu before the admininster menu
      $params = array_slice($params, 0, $posOfAdminMenu, true)
        + $formProcessorMenu + array_slice($params, $posOfAdminMenu, NULL, true);
    }
    
    /**
     * Helper function for getting the highest key in the navigation menu.
     *
     * Taken from http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu.
     *
     * @param array $menuArray
     * @return int
     */
    function _form_processor_getMenuKeyMax($menuArray) {
      $max = array(max(array_keys($menuArray)));
      foreach($menuArray as $v) {
        if (!empty($v['child'])) {
          $max[] = _form_processor_getMenuKeyMax($v['child']);
        }
      }
      return max($max);
    }
    
    
    
    jaapjansma's avatar
    jaapjansma committed
    /**
     * Implements hook_civicrm_config().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
     */
    function form_processor_civicrm_config(&$config) {
      _form_processor_civix_civicrm_config($config);
    }
    
    /**
     * Implements hook_civicrm_xmlMenu().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu
     */
    function form_processor_civicrm_xmlMenu(&$files) {
      _form_processor_civix_civicrm_xmlMenu($files);
    }
    
    /**
     * Implements hook_civicrm_install().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
     */
    function form_processor_civicrm_install() {
      _form_processor_civix_civicrm_install();
    }
    
    /**
     * Implements hook_civicrm_postInstall().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall
     */
    function form_processor_civicrm_postInstall() {
      _form_processor_civix_civicrm_postInstall();
    }
    
    /**
     * Implements hook_civicrm_uninstall().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
     */
    function form_processor_civicrm_uninstall() {
      _form_processor_civix_civicrm_uninstall();
    }
    
    /**
     * Implements hook_civicrm_enable().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
     */
    function form_processor_civicrm_enable() {
      _form_processor_civix_civicrm_enable();
    }
    
    /**
     * Implements hook_civicrm_disable().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
     */
    function form_processor_civicrm_disable() {
      _form_processor_civix_civicrm_disable();
    }
    
    /**
     * Implements hook_civicrm_upgrade().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
     */
    function form_processor_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
      return _form_processor_civix_civicrm_upgrade($op, $queue);
    }
    
    /**
     * Implements hook_civicrm_managed().
     *
     * Generate a list of entities to create/deactivate/delete when this module
     * is installed, disabled, uninstalled.
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_managed
     */
    function form_processor_civicrm_managed(&$entities) {
      _form_processor_civix_civicrm_managed($entities);
    }
    
    /**
     * Implements hook_civicrm_caseTypes().
     *
     * Generate a list of case-types.
     *
     * Note: This hook only runs in CiviCRM 4.4+.
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_caseTypes
     */
    function form_processor_civicrm_caseTypes(&$caseTypes) {
      _form_processor_civix_civicrm_caseTypes($caseTypes);
    }
    
    /**
     * Implements hook_civicrm_angularModules().
     *
     * Generate a list of Angular modules.
     *
     * Note: This hook only runs in CiviCRM 4.5+. It may
     * use features only available in v4.6+.
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_angularModules
     */
    function form_processor_civicrm_angularModules(&$angularModules) {
      _form_processor_civix_civicrm_angularModules($angularModules);
    }
    
    /**
     * Implements hook_civicrm_alterSettingsFolders().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders
     */
    function form_processor_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
      _form_processor_civix_civicrm_alterSettingsFolders($metaDataFolders);
    }
    
    // --- Functions below this ship commented out. Uncomment as required. ---
    
    /**
     * Implements hook_civicrm_preProcess().
     *
     * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
     *
    function form_processor_civicrm_preProcess($formName, &$form) {
    
    } // */