Fix dev/core#4852 - View notes renders as form instead of page
authorcolemanw <coleman@civicrm.org>
Tue, 12 Dec 2023 01:26:45 +0000 (20:26 -0500)
committercolemanw <coleman@civicrm.org>
Tue, 12 Dec 2023 01:34:26 +0000 (20:34 -0500)
CRM/Note/Form/Note.php
templates/CRM/Note/Form/Note.tpl

index b243a2719a0836d6033751a9d7c9a5dc9507390c..9972cc6c3d8b2755c05339a988aea51f42f7dcf8 100644 (file)
@@ -98,6 +98,10 @@ class CRM_Note_Form_Note extends CRM_Core_Form {
    * @return void
    */
   public function buildQuickForm() {
+    if ($this->_action & CRM_Core_Action::VIEW) {
+      $this->view();
+      return;
+    }
     if ($this->_action & CRM_Core_Action::DELETE) {
       $this->addButtons([
           [
@@ -177,4 +181,24 @@ class CRM_Note_Form_Note extends CRM_Core_Form {
     CRM_Core_Session::setStatus(ts('Your Note has been saved.'), ts('Saved'), 'success');
   }
 
+  /**
+   * View details of a note.
+   */
+  private function view() {
+    $note = \Civi\Api4\Note::get()
+      ->addSelect('*', 'privacy:label')
+      ->addWhere('id', '=', $this->_id)
+      ->execute()
+      ->single();
+    $note['privacy'] = $note['privacy:label'];
+    $this->assign('note', $note);
+
+    $comments = CRM_Core_BAO_Note::getNoteTree($this->_id, 1);
+    $this->assign('comments', $comments);
+
+    // add attachments part
+    $currentAttachmentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_note', $this->_id);
+    $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
+  }
+
 }
index d458d25a95f012971f03f1774b1904e84a8b4405..b02126a44926fcbf832b2679357d4bdbd5c24ea5 100644 (file)
@@ -7,8 +7,41 @@
  | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
 *}
+{* View action *}
+{if ($action eq 4)}
+  <div class="crm-block crm-content-block crm-note-view-block">
+    <table class="crm-info-panel">
+      <tr><td class="label">{ts}Subject{/ts}</td><td>{$note.subject}</td></tr>
+      <tr><td class="label">{ts}Date:{/ts}</td><td>{$note.note_date|crmDate}</td></tr>
+      <tr><td class="label">{ts}Modified Date:{/ts}</td><td>{$note.modified_date|crmDate}</td></tr>
+      <tr><td class="label">{ts}Privacy:{/ts}</td><td>{$note.privacy}</td></tr>
+      <tr><td class="label">{ts}Note:{/ts}</td><td>{$note.note|nl2br}</td></tr>
+
+        {if $currentAttachmentInfo}
+            {include file="CRM/Form/attachment.tpl"}
+        {/if}
+    </table>
+    <div class="crm-submit-buttons">
+        {crmButton class="cancel" icon="times" p='civicrm/contact/view' q="selectedChild=note&reset=1&cid=`$note.entity_id`"}{ts}Done{/ts}{/crmButton}
+    </div>
+
+      {if $comments}
+        <fieldset>
+          <legend>{ts}Comments{/ts}</legend>
+          <table class="display">
+            <thead>
+            <tr><th>{ts}Comment{/ts}</th><th>{ts}Created By{/ts}</th><th>{ts}Date{/ts}</th><th>{ts}Modified Date{/ts}</th></tr>
+            </thead>
+              {foreach from=$comments item=comment}
+                <tr class="{cycle values='odd-row,even-row'}"><td>{$comment.note}</td><td>{$comment.createdBy}</td><td>{$comment.note_date}</td><td>{$comment.modified_date}</td></tr>
+              {/foreach}
+          </table>
+        </fieldset>
+      {/if}
+
+  </div>
 {* Delete action *}
-{if ($action eq 8)}
+{elseif ($action eq 8)}
   <div class=status>{ts}Are you sure you want to delete this note?{/ts}</div>
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location=''}</div>
 {* Create/Update actions *}