forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEUSPRT-234: Add a new date format type to the date formats screen ca…
…lled “Date Format: Activity Feed”
- Loading branch information
1 parent
84daf75
commit 39efa58
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Add ActivityDateFormat To DateSettings BuildForm Hook Class. | ||
*/ | ||
class CRM_Civicase_Hook_BuildForm_AddCaseActivityDateFormatToDateSettings { | ||
|
||
/** | ||
* Adds Activity DateFormat To Date Settings Form. | ||
* | ||
* @param CRM_Core_Form $form | ||
* Form Class object. | ||
* @param string $formName | ||
* Form Name. | ||
*/ | ||
public function run(CRM_Core_Form &$form, $formName) { | ||
if (!$this->shouldRun($formName)) { | ||
return; | ||
} | ||
|
||
$this->addActivityDateFormatField($form); | ||
} | ||
|
||
/** | ||
* Checks if this shook should run. | ||
* | ||
* @param string $formName | ||
* Form Name. | ||
* | ||
* @return bool | ||
* True if the hook should run. | ||
*/ | ||
public function shouldRun($formName) { | ||
return $formName == CRM_Admin_Form_Setting_Date::class; | ||
} | ||
|
||
/** | ||
* Add activity date format field. | ||
* | ||
* @param CRM_Core_Form $form | ||
* Form Class object. | ||
*/ | ||
private function addActivityDateFormatField($form) { | ||
$name = 'civiCaseActivityDateformat'; | ||
$fieldName = '_qf_' . $name; | ||
$field = [ | ||
$fieldName => [ | ||
'html_type' => 'text', | ||
'title' => ts('Date Format: Activity Feed'), | ||
'weight' => 5, | ||
], | ||
]; | ||
|
||
$form->add('text', $fieldName, $field[$fieldName]['title'], $field[$fieldName]['attributes']); | ||
$value = Civi::settings()->get($name) ?? '%d %b %Y'; | ||
$form->setDefaults(array_merge($form->_defaultValues, [$fieldName => $value])); | ||
|
||
CRM_Core_Region::instance('form-body')->add([ | ||
'template' => "CRM/Civicase/Form/CaseActivityDateFormat.tpl", | ||
]); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/** | ||
* Save Activity DateFormat. | ||
*/ | ||
class CRM_Civicase_Hook_PostProcess_SaveCaseActivityDateFormat { | ||
|
||
/** | ||
* Saves The Activity DateFormat field. | ||
* | ||
* @param string $formName | ||
* Form Name. | ||
* @param CRM_Core_Form $form | ||
* Form Class object. | ||
*/ | ||
public function run($formName, CRM_Core_Form $form) { | ||
if (!$this->shouldRun($formName)) { | ||
return; | ||
} | ||
|
||
$this->saveCaseActivityDateFormatField($form); | ||
} | ||
|
||
/** | ||
* Checks if this shook should run. | ||
* | ||
* @param string $formName | ||
* Form Name. | ||
* | ||
* @return bool | ||
* True if the hook should run. | ||
*/ | ||
public function shouldRun($formName) { | ||
return $formName == CRM_Admin_Form_Setting_Date::class; | ||
} | ||
|
||
/** | ||
* Saves The Activity DateFormat field. | ||
* | ||
* @param CRM_Core_Form $form | ||
* Form Class object. | ||
*/ | ||
public function saveCaseActivityDateFormatField(CRM_Core_Form &$form) { | ||
$values = $form->getVar('_submitValues'); | ||
if (!empty($values['_qf_civiCaseActivityDateformat'])) { | ||
Civi::settings()->set('civiCaseActivityDateformat', $values['_qf_civiCaseActivityDateformat']); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<table class="form-layout-compressed"> | ||
<tr class="crm-date-form-block-_qf_civiCaseActivityDateformat"> | ||
<td class="label">{$form._qf_civiCaseActivityDateformat.label}</td> | ||
<td>{$form._qf_civiCaseActivityDateformat.html}</td> | ||
</tr> | ||
</table> | ||
|
||
{literal} | ||
<script> | ||
CRM.$('.crm-date-form-block-dateformatTime').last().after(CRM.$('.crm-date-form-block-_qf_civiCaseActivityDateformat')) | ||
</script> | ||
{/literal} |