You can do this with hooks, in folder: web/apps/ create file init-custom.php and then here paste bellow code:there is a way to set as "required field" the customer Tracking Domain choice ?
hooks()->addAction('controller_action_save_data', function(CAttributeCollection $collection) {
// Make sure you are in the customer area
if (!apps()->isAppName('customer')) {
return;
}
/** @var ActiveRecord $model */
$model = $collection->itemAt('campaign');
$customer = $model->list->customer;
$canSelectTrackingDomains = $customer->getGroupOption('tracking_domains.can_select_for_campaigns', 'no') == 'yes';
// Make sure option is enabled
if (!$canSelectTrackingDomains) {
return;
}
$controller = $collection->itemAt('controller');
// Continue only for the campaigns and the setup action
if ($controller->getId() != 'campaigns' || $controller->getAction()->getId() != 'setup') {
return;
}
if (!$collection->itemAt('success')) {
return;
}
// Check if tracking domain is empty
if (empty($model->option->tracking_domain_id)) {
// Clear all notifications
notify()->clearAll();
// Add notification message to display
notify()->addError(t('app', 'Your form has a few errors, please fix them and try again!'));
$collection->success = false;
$model->option->addError('tracking_domain_id', t('app', 'This field is required'));
}
});
hooks()->addAction('controller_action_save_data', function(CAttributeCollection $collection) {
// Make sure you are in the customer area and the customer is logged in
if (!apps()->isAppName('customer') || !customer()->getId()) {
return;
}
$controller = $collection->itemAt('controller');
// Continue only for the campaigns and the setup action
if (empty($controller) || $controller->getId() != 'campaigns' || $controller->getAction()->getId() != 'setup') {
return;
}
if (!$collection->itemAt('success')) {
return;
}
/** @var ActiveRecord $model */
$model = $collection->itemAt('campaign');
$customer = $model->list->customer;
$canSelectTrackingDomains = $customer->getGroupOption('tracking_domains.can_select_for_campaigns', 'no') == 'yes';
// Make sure option is enabled
if (!$canSelectTrackingDomains) {
return;
}
// Check if tracking domain is empty
if (empty($model->option->tracking_domain_id)) {
// Clear all notifications
notify()->clearAll();
// Add notification message to display
notify()->addError(t('app', 'Your form has a few errors, please fix them and try again!'));
$collection->success = false;
$model->option->addError('tracking_domain_id', t('app', 'This field is required'));
}
});