Convert view recurring contribution to use EntityPageTrait
authorMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 27 Apr 2020 22:39:53 +0000 (23:39 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 27 Apr 2020 22:39:53 +0000 (23:39 +0100)
CRM/Contribute/Page/ContributionRecur.php
CRM/Core/Page/EntityPageTrait.php

index 2942fcbf101a99e9cecb2a55fdfc9abb12798dca..ef68f424c7c1fa47313d45158742b60d4c197456 100644 (file)
  */
 class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page {
 
-  public static $_links = NULL;
-  public $_permission = NULL;
-  public $_contactId = NULL;
-  public $_id = NULL;
-  public $_action = NULL;
+  use CRM_Core_Page_EntityPageTrait;
+
+  /**
+   * @return string
+   */
+  public function getDefaultEntity() {
+    return 'ContributionRecur';
+  }
+
+  protected function getDefaultAction() {
+    return 'view';
+  }
 
   /**
    * View details of a recurring contribution.
    */
   public function view() {
-    if (empty($this->_id)) {
+    if (empty($this->getEntityId())) {
       CRM_Core_Error::statusBounce('Recurring contribution not found');
     }
 
     try {
       $contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', [
-        'id' => $this->_id,
+        'id' => $this->getEntityId(),
       ]);
     }
     catch (Exception $e) {
-      CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->_id);
+      CRM_Core_Error::statusBounce('Recurring contribution not found (ID: ' . $this->getEntityId());
     }
 
     $contributionRecur['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName(
@@ -81,21 +88,7 @@ class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page {
   }
 
   public function preProcess() {
-    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'view');
-    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
-    $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
-    $this->assign('contactId', $this->_contactId);
-
-    // check logged in url permission
-    CRM_Contact_Page_View::checkUserPermission($this);
-
-    $this->assign('action', $this->_action);
-
-    if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) {
-      // demote to view since user does not have edit contrib rights
-      $this->_permission = CRM_Core_Permission::VIEW;
-      $this->assign('permission', 'view');
-    }
+    $this->preProcessQuickEntityPage();
   }
 
   /**
@@ -107,7 +100,7 @@ class CRM_Contribute_Page_ContributionRecur extends CRM_Core_Page {
   public function run() {
     $this->preProcess();
 
-    if ($this->_action & CRM_Core_Action::VIEW) {
+    if ($this->isViewContext()) {
       $this->view();
     }
 
index 2f043957f49cd644d9df3895083905e12715d93d..ab93fb483e3c536e05111bbd5713d3ef08bd7948 100644 (file)
@@ -124,8 +124,15 @@ trait CRM_Core_Page_EntityPageTrait {
     return NULL;
   }
 
+  /**
+   * @return string
+   */
+  protected function getDefaultAction() {
+    return 'browse';
+  }
+
   public function preProcessQuickEntityPage() {
-    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
+    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, $this->getDefaultAction());
     $this->assign('action', $this->getAction());
 
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);