1

In the CiviCRM system I work on, activities created for a specific case can have the priority "normal" or "urgent". This attribute is set by the user when creating the activity inside the CaseView. Internally, the "priority_id" of this activity is set to 1 == "urgent" or 2 == "normal". Now, I want to mark the activities with priority "urgent" in another color when listed in the CaseView as well as in the Case Overview (Cases > My Cases). I started with the first task (changing the activity layout in the CaseView activity list).

I tried modifying the sites/all/modules/civicrm/templates/CRM/Case/Form/ActivityToCase.tpl at line 23, added the following if-clause. This template is included in sites/all/modules/civicrm/templates/CRM/Case/Form/CaseView.tpl in line 259, which seemed like the correct place in the CaseView.tpl for the activities to appear. I added:

{if $form.priority_id == 1}
   <td class="label urgent">{$form.file_on_case_activity_subject.label}</td>
{elseif $form.priority_id == 2}
   <td class="label">{$form.file_on_case_activity_subject.label}</td>
{/if}

where before we only had:

<td class="label">{$form.file_on_case_activity_subject.label}</td>

When this didn't work, I tried to set an "urgent" class to the $form.file_on_case_activity_subject.html as well:

{if $form.priority_id == 1}
          <td class="label urgent">{$form.file_on_case_activity_subject.label}</td>
          <td class="urgent">{$form.file_on_case_activity_subject.html}<br />
            <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span>
          </td>
        {elseif $form.priority_id == 2}
        <td class="label">{$form.file_on_case_activity_subject.label}</td>
          <td>{$form.file_on_case_activity_subject.html}<br />
            <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span>
          </td>
        {/if}

where before we only had:

<td class="label">{$form.file_on_case_activity_subject.label}</td>
<td>{$form.file_on_case_activity_subject.html}<br />
            <span class="description">{ts}You can modify the activity subject before filing.{/ts}</span>
          </td>

As this didn't work either, I suppose I am modifying the wrong place. Any hint anyone?

Edit: I created an extension with the following code, but it doesn't work yet:

function mark_urgent_activities_civicrm_buildForm($formName, &$form) {
  if ($formName == 'CRM_Case_Form_CaseView') {
    CRM_Core_Resources::singleton()->addStyle('#crm-container table.nestedActivitySelector tr.priority-urgent {background-color: orange;}');
  }
}

Edit2: Accessing the elements with priority-urgent class works in the css file, both as

.priority-urgent {
font-weight: bold;
}

and

#crm-container table.nestedActivitySelector tr.priority-urgent {
font-weight: bold;
}

The (background / font) color doesn't work yet, but I suppose that's only because element cannot have background color.

  • It worked when I tested it - but I didn't restrict to CRM_Case_Form_CaseView. The table is created by magic after the page loads so maybe there's a timing issue if you restrict the form. The background-color worked for me - maybe you have other customizations conflicting? – Demerit Oct 8 at 14:51
3

If I'm understanding correctly, all you need to do is make an extension and call CRM_Core_Resources::singleton()->addStyle() in hook_buildForm as described at https://docs.civicrm.org/dev/en/latest/framework/resources/#css-stylesheets since activities with priority urgent already get class priority-urgent added to the <tr> element in the table that lists the activities.

e.g. CRM_Core_Resources::singleton()->addStyle('#crm-container table.nestedActivitySelector tr.priority-urgent {background-color: orange;}');

The #crm-container table.nestedActivitySelector part is required because otherwise the more specific css target from core gets applied instead.

| improve this answer | |
  • Can you tell me where exactly activities with priority urgent get the class priority-urgent added to the <tr> element? And where does the more specific css target from core get applied? – emma Oct 8 at 9:39
  • grep -r priority-urgent * - says it's in CRM/Case/BAO/Case.php - line 1022 (I'm using 5.31/dev - line number might be slightly different in other versions.) Similarly the more specific css part is in css/civicrm.css. – Demerit Oct 8 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.