Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-17570

Add hook to permit use of custom callback paths

    Details

    • Type: Improvement
    • Status: In Progress
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 4.7
    • Fix Version/s: Unscheduled
    • Component/s: None
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      Developer Doc
    • Funding Source:
      Core Team Funds

      Description

      I asked today if it was possible to sit CiviCRM Angular pages (from an extension) at a custom callback relative to CMS root (so, example.org/donate instead of example.org/civicrm/a or example.org/civicrm/contribute/transact?id=1). Have played with a proof of concept for Drupal routing and it's a pretty small addition, but it might need some thought to generalise for other CMS (and if it's Drupal specific you can use a Drupal module to do the same).

      In CRM_Utils_Hook we add a new hook, eg hook_civicrm_alterRoutes -

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
        /**
         * This hook is called when identifying CMS route callbacks.
         *
         * @param array $params
         *   Varies by CMS. Hmm.
         */
        public static function alterRoutes(&$params, $context = NULL) {
          return self::singleton()->invoke(1, $params, self::$_nullObject,
            self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
            'civicrm_alterRoutes'
          );
        }
      

      In civicrm.module we introduce the hook civicrm_menu().

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      /**
       * Implements hook_menu().
       */
      function civicrm_menu() {
        if (!civicrm_initialize()) {
          return;
        }
      
        $items = array(
          'civicrm' => array(
            'title' => 'CiviCRM',
            'access callback' => TRUE,
            'page callback' => 'civicrm_invoke',
            'type' => 4,
            'weight' => 0,
          ),
          // administration section for civicrm integration modules.
          'admin/config/civicrm' => array(
            'title' => 'CiviCRM',
            'description' => 'Configure CiviCRM integration modules.',
            'position' => 'left',
            'weight' => -10,
            'page callback' => 'system_admin_menu_block_page',
            'access arguments' => array('access administration pages'),
            'file' => 'system.admin.inc',
            'file path' => drupal_get_path('module', 'system'),
          ),
        );
      
        CRM_Utils_Hook::alterRoutes($items);
      
        return $items;
      }
      

      In the extension we can activate CiviCRM (and subpages!) by fiddling a little.

      Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      /**
       * Implements hook_civicrm_alterRoutes().
       */
      function boldrain_civicrm_alterRoutes(&$items) {
        $items['donate'] = $items['civicrm'];
        $items['donate']['title callback'] = '_boldrain_hacky_title_callback';
      }
      
      /**
       * It's hacky.
       */
      function _boldrain_hacky_title_callback() {
        // Rewrite $_GET['q'] when loading page to activate CiviCRM.
        $_GET['q'] = 'civicrm/a';
      }
      

      Hope the formatting in this ticket worked.

      (I can PR this, but it's just an idea atm. It works for me currently to activate Angular code at an alternate URL which doesn't have the civicrm prefix, with no other tweaks required apparently.)

        Attachments

          Activity

            People

            • Assignee:
              xurizaemon Chris Burgess
              Reporter:
              xurizaemon Chris Burgess
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: