Add getEventID() - this is part of an effort to ensure consistency
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 14 Sep 2023 23:42:32 +0000 (11:42 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 14 Sep 2023 23:48:07 +0000 (11:48 +1200)
All event & participant forms should have public api functions for
getParticipantID() and getEventID() (participant ID
not so relevant here

CRM/Event/Page/EventInfo.php

index fe4d6c8f636c4a91a91eca5d0b7967f586a644cc..525afae415e45540f65706b09c2d44b8841bfda5 100644 (file)
@@ -30,12 +30,10 @@ class CRM_Event_Page_EventInfo extends CRM_Core_Page {
    * @return void
    */
   public function run() {
-    //get the event id.
-    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $config = CRM_Core_Config::singleton();
     // ensure that the user has permission to see this page
     if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW,
-      $this->_id, 'view event info'
+      $this->getEventID(), 'view event info'
     )
     ) {
       CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
@@ -331,11 +329,28 @@ class CRM_Event_Page_EventInfo extends CRM_Core_Page {
     return parent::run();
   }
 
+  /**
+   * Get the selected Event ID.
+   *
+   * @api This function will not change in a minor release and is supported for
+   * use outside of core. This annotation / external support for properties
+   * is only given where there is specific test cover.
+   *
+   * @return int|null
+   */
+  public function getEventID(): int {
+    if (!isset($this->_id)) {
+      $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
+      $this->_id = $id;
+    }
+    return (int) $this->_id;
+  }
+
   /**
    * @return string
    */
   public function getTemplateFileName() {
-    if ($this->_id) {
+    if ($this->getEventID()) {
       $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
       $template = CRM_Core_Page::getTemplate();