* array(string $value => string $label).
* Ex: array('assignee' => 'Activity Assignee').
*/
- public function getRecipientTypes(): array {
- return \CRM_Core_OptionGroup::values('activity_contacts');
+ public static function getRecipientTypes(): array {
+ return \CRM_Core_OptionGroup::values('activity_contacts') + parent::getRecipientTypes();
}
/**
$mappings = CRM_Core_BAO_ActionSchedule::getMappings();
$selectedMapping = $mappings[$mappingID ?: 1];
- $entityRecipientLabels = $selectedMapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule::getAdditionalRecipients();
+ $entityRecipientLabels = $selectedMapping::getRecipientTypes();
$this->assign('entityMapping', json_encode(
CRM_Utils_Array::collectMethod('getEntityTable', $mappings)
));
$mapping = CRM_Core_BAO_ActionSchedule::getMapping($_GET['mappingID']);
$dateFieldLabels = $mapping ? $mapping->getDateFields() : [];
- // The UX here is quirky -- for "Activity" types, there's a simple drop "Recipients"
- // dropdown which is always displayed. For other types, the "Recipients" drop down is
- // conditional upon the weird isLimit ('Limit To / Also Include / Neither') dropdown.
- $noThanksJustKidding = !$_GET['isLimit'];
- if ($mapping instanceof CRM_Activity_ActionMapping || !$noThanksJustKidding) {
- $entityRecipientLabels = $mapping ? ($mapping->getRecipientTypes() + CRM_Core_BAO_ActionSchedule::getAdditionalRecipients()) : [];
- }
- else {
- $entityRecipientLabels = CRM_Core_BAO_ActionSchedule::getAdditionalRecipients();
- }
+ $entityRecipientLabels = $mapping ? $mapping->getRecipientTypes() : [];
$recipientMapping = array_combine(array_keys($entityRecipientLabels), array_keys($entityRecipientLabels));
$output = [
* array(string $value => string $label).
* Ex: array('assignee' => 'Activity Assignee').
*/
- public function getRecipientTypes(): array {
- return [
- 'soft_credit_type' => ts('Soft Credit Role'),
- ];
+ public static function getRecipientTypes(): array {
+ $types = parent::getRecipientTypes();
+ $types['soft_credit_type'] = ts('Soft Credit Role');
+ return $types;
}
/**
return self::getMapping($values['mapping_id'])::getLimitToOptions();
}
+ /**
+ * Provides pseudoconstant list for `recipient` field.
+ * @return array|null
+ */
+ public static function getRecipientOptions(string $fieldName, array $params): ?array {
+ $values = self::fillValues($params['values'], ['mapping_id']);
+ if (!$values['mapping_id']) {
+ return Civi\ActionSchedule\MappingBase::getRecipientTypes();
+ }
+ return self::getMapping($values['mapping_id'])::getRecipientTypes();
+ }
+
/**
* Provides pseudoconstant list for `entity_status` field.
* @return array
}
/**
- * Get the list of generic recipient types supported by all entities/mappings.
- *
- * @return array
- * array(mixed $value => string $label).
+ * @deprecated
*/
public static function getAdditionalRecipients(): array {
+ CRM_Core_Error::deprecatedFunctionWarning('APIv4 getFields');
return [
'manual' => ts('Choose Recipient(s)'),
'group' => ts('Select Group'),
*
* Generated from xml/schema/CRM/Core/ActionSchedule.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:0daacf629f554f84f06ac36343f70bbc)
+ * (GenCodeChecksum:08e73c2f0aa86b5eab3e67f2a707b2bf)
*/
/**
'bao' => 'CRM_Core_BAO_ActionSchedule',
'localizable' => 0,
'html' => [
+ 'type' => 'Select',
'label' => ts("Recipient"),
+ 'controlField' => 'mapping_id',
+ ],
+ 'pseudoconstant' => [
+ 'callback' => 'CRM_Core_BAO_ActionSchedule::getRecipientOptions',
],
'add' => '3.4',
],
* array(string $value => string $label).
* Ex: array('assignee' => 'Activity Assignee').
*/
- public function getRecipientTypes(): array {
- return \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
+ public static function getRecipientTypes(): array {
+ $types = \CRM_Core_OptionGroup::values('event_contacts', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name');
+ return $types + parent::getRecipientTypes();
}
/**
return [];
}
- public function getRecipientTypes(): array {
- return [];
+ public static function getRecipientTypes(): array {
+ return [
+ 'manual' => ts('Choose Recipient(s)'),
+ 'group' => ts('Select Group'),
+ ];
}
public function validateSchedule($schedule): array {
* array(string $value => string $label).
* Ex: array('assignee' => 'Activity Assignee').
*/
- public function getRecipientTypes(): array;
+ public static function getRecipientTypes(): array;
/**
* Get a list of recipients which match the given type.
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace api\v4\Entity;
+
+use api\v4\Api4TestBase;
+use Civi\Api4\ActionSchedule;
+
+/**
+ * Test ActionSchedule functionality
+ *
+ * @group headless
+ */
+class ActionScheduleTest extends Api4TestBase {
+
+ public function testGetOptionsBasic() {
+ $fields = ActionSchedule::getFields(FALSE)
+ ->setLoadOptions(TRUE)
+ ->execute()
+ ->indexBy('name');
+
+ $this->assertArrayHasKey('1', $fields['mapping_id']['options']);
+ $this->assertArrayHasKey('contribpage', $fields['mapping_id']['options']);
+
+ $this->assertArrayHasKey('day', $fields['start_action_unit']['options']);
+ $this->assertArrayHasKey('week', $fields['repetition_frequency_unit']['options']);
+ $this->assertArrayHasKey('month', $fields['end_frequency_unit']['options']);
+
+ $this->assertArrayHasKey('manual', $fields['recipient']['options']);
+ $this->assertArrayHasKey('group', $fields['recipient']['options']);
+
+ $this->assertArrayHasKey('1', $fields['limit_to']['options']);
+ $this->assertArrayHasKey('2', $fields['limit_to']['options']);
+ }
+
+}
<comment>Recipient</comment>
<html>
<label>Recipient</label>
+ <type>Select</type>
+ <controlField>mapping_id</controlField>
</html>
+ <pseudoconstant>
+ <callback>CRM_Core_BAO_ActionSchedule::getRecipientOptions</callback>
+ </pseudoconstant>
<add>3.4</add>
</field>
<field>