From 8775c48a8eb772fd8d48e62be4e70caa1cf04241 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 12 Jun 2018 20:34:31 -0700 Subject: [PATCH] Generate skeletal base-page based on `server_route` values --- ext/afform/CRM/Afform/Page/AfformBase.php | 21 +++++++++++++++++++ ext/afform/afform.php | 18 ++++++++++++++++ .../templates/CRM/Afform/Page/AfformBase.tpl | 9 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 ext/afform/CRM/Afform/Page/AfformBase.php create mode 100644 ext/afform/templates/CRM/Afform/Page/AfformBase.tpl diff --git a/ext/afform/CRM/Afform/Page/AfformBase.php b/ext/afform/CRM/Afform/Page/AfformBase.php new file mode 100644 index 0000000000..bfea8a8540 --- /dev/null +++ b/ext/afform/CRM/Afform/Page/AfformBase.php @@ -0,0 +1,21 @@ +';print_r(func_get_args());exit(); + list ($pagePath, $pageArgs) = func_get_args(); + + // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml + CRM_Utils_System::setTitle(E::ts('AfformBase')); + + // Example: Assign a variable for use in a template + $this->assign('currentTime', date('Y-m-d H:i:s')); + + $this->assign('afform', $pageArgs['afform']); + + parent::run(); + } + +} diff --git a/ext/afform/afform.php b/ext/afform/afform.php index 084a2cd3cf..01305db2e8 100644 --- a/ext/afform/afform.php +++ b/ext/afform/afform.php @@ -199,6 +199,24 @@ function afform_civicrm_buildAsset($asset, $params, &$mimeType, &$content) { $content = $smarty->fetch('afform/FormAsDirective.tpl'); } +/** + * Implements hook_civicrm_alterMenu(). + */ +function afform_civicrm_alterMenu(&$items) { + $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 + ]; + } + } + print_r($items); +} + /** * @param $name * @return string diff --git a/ext/afform/templates/CRM/Afform/Page/AfformBase.tpl b/ext/afform/templates/CRM/Afform/Page/AfformBase.tpl new file mode 100644 index 0000000000..4beb737db3 --- /dev/null +++ b/ext/afform/templates/CRM/Afform/Page/AfformBase.tpl @@ -0,0 +1,9 @@ +

This new page is generated by CRM/Afform/Page/AfformBase.php

+ +{* Example: Display a variable directly *} +

The current time is {$currentTime}

+ +{* Example: Display a translated string -- which happens to include a variable *} +

{ts 1=$currentTime}(In your native language) The current time is %1.{/ts}

+ +

Please open "{$afform}"

\ No newline at end of file -- 2.25.1