setDefinition('afform_scanner', new \Symfony\Component\DependencyInjection\Definition( 'CRM_Afform_AfformScanner', array() )); } /** * Implements hook_civicrm_config(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config */ function afform_civicrm_config(&$config) { _afform_civix_civicrm_config($config); } /** * Implements hook_civicrm_xmlMenu(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_xmlMenu */ function afform_civicrm_xmlMenu(&$files) { _afform_civix_civicrm_xmlMenu($files); } /** * Implements hook_civicrm_install(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function afform_civicrm_install() { _afform_civix_civicrm_install(); } /** * Implements hook_civicrm_postInstall(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall */ function afform_civicrm_postInstall() { _afform_civix_civicrm_postInstall(); } /** * Implements hook_civicrm_uninstall(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall */ function afform_civicrm_uninstall() { _afform_civix_civicrm_uninstall(); } /** * Implements hook_civicrm_enable(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable */ function afform_civicrm_enable() { _afform_civix_civicrm_enable(); } /** * Implements hook_civicrm_disable(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable */ function afform_civicrm_disable() { _afform_civix_civicrm_disable(); } /** * Implements hook_civicrm_upgrade(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade */ function afform_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) { return _afform_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 afform_civicrm_managed(&$entities) { _afform_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 afform_civicrm_caseTypes(&$caseTypes) { _afform_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 afform_civicrm_angularModules(&$angularModules) { _afform_civix_civicrm_angularModules($angularModules); $scanner = Civi::service('afform_scanner'); $names = array_keys($scanner->findFilePaths()); foreach ($names as $name) { $meta = $scanner->getMeta($name); $angularModules[_afform_angular_module_name($name, 'camel')] = [ 'ext' => E::LONG_NAME, 'js' => ['assetBuilder://afform.js?name=' . urlencode($name)], 'requires' => $meta['requires'], 'basePages' => [], ]; // FIXME: The HTML layout template is embedded in the JS asset. // This works at runtime for basic usage, but it bypasses // the hook_alterAngular infrastructure, and I'm not sure translation works. // We should update core so that 'partials' can be specified more dynamically. } } /** * Implements hook_civicrm_alterSettingsFolders(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterSettingsFolders */ function afform_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { _afform_civix_civicrm_alterSettingsFolders($metaDataFolders); } /** * Implements hook_civicrm_entityTypes(). * * Declare entity types provided by this module. * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_entityTypes */ function afform_civicrm_entityTypes(&$entityTypes) { _afform_civix_civicrm_entityTypes($entityTypes); } // --- Functions below this ship commented out. Uncomment as required. --- /** * Implements hook_civicrm_buildAsset(). */ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) { if ($asset !== 'afform.js') { return; } if (empty($params['name'])) { throw new RuntimeException("Missing required parameter: afform.js?name=NAME"); } $name = $params['name']; // Hmm?? $scanner = new CRM_Afform_AfformScanner(); // Hmm?? afform_scanner $scanner = Civi::service('afform_scanner'); $meta = $scanner->getMeta($name); // Hmm?? $scanner = new CRM_Afform_AfformScanner(); $smarty = CRM_Core_Smarty::singleton(); $smarty->assign('afform', [ 'camel' => _afform_angular_module_name($name, 'camel'), 'meta' => $meta, 'metaJson' => json_encode($meta), 'layout' => file_get_contents($scanner->findFilePath($name, 'aff.html')) ]); $mimeType = 'text/javascript'; $content = $smarty->fetch('afform/AfformAngularModule.tpl'); } /** * Implements hook_civicrm_alterMenu(). */ function afform_civicrm_alterMenu(&$items) { if (Civi::container()->has('afform_scanner')) { $scanner = Civi::service('afform_scanner'); } else { // During installation... $scanner = new CRM_Afform_AfformScanner(); } foreach ($scanner->getMetas() as $name => $meta) { if (!empty($meta['server_route'])) { $items[$meta['server_route']] = [ 'page_callback' => 'CRM_Afform_Page_AfformBase', 'page_arguments' => 'afform=' . urlencode($name), 'title' => CRM_Utils_Array::value('title', $meta, ''), 'access_arguments' => [['access CiviCRM'], 'and'], // FIXME 'is_public' => $meta['is_public'], ]; } } } /** * @param string $fileBaseName * Ex: foo-bar * @param string $format * 'camel' or 'dash'. * @return string * Ex: 'FooBar' or 'foo-bar'. */ function _afform_angular_module_name($fileBaseName, $format = 'camel') { switch ($format) { case 'camel': $camelCase = ''; foreach (explode('-', $fileBaseName) as $shortNamePart) { $camelCase .= ucfirst($shortNamePart); } return strtolower($camelCase{0}) . substr($camelCase, 1); case 'dash': return strtolower(implode('-', array_filter(preg_split('/(?=[A-Z])/', $fileBaseName)))); default: throw new \Exception("Unrecognized format"); } } /** * Implements hook_civicrm_preProcess(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess * function afform_civicrm_preProcess($formName, &$form) { } // */ /** * Implements hook_civicrm_navigationMenu(). * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_navigationMenu * function afform_civicrm_navigationMenu(&$menu) { _afform_civix_insert_navigation_menu($menu, 'Mailings', array( 'label' => E::ts('New subliminal message'), 'name' => 'mailing_subliminal_message', 'url' => 'civicrm/mailing/subliminal', 'permission' => 'access CiviMail', 'operator' => 'OR', 'separator' => 0, )); _afform_civix_navigationMenu($menu); } // */