5 * Display a block with opt-in settings.
7 * The file `opt-in.disabled.php` is ignored by default. To enable, you should
8 * either rename it to `opt-in.civi-setup.php` or symlink it.
11 if (!defined('CIVI_SETUP')) {
12 exit("Installation plugins must only be loaded by the installer.\n");
15 // First pass: initialize 'settings' block.
16 \Civi\Setup
::dispatcher()
17 ->addListener('civi.setupui.boot', function (\Civi\Setup\UI\Event\UIBootEvent
$e) {
18 \Civi\Setup
::log()->info(sprintf('[%s] Register blocks', basename(__FILE__
)));
20 $e->getCtrl()->blocks
['opt-in'] = array(
23 'file' => __DIR__
. DIRECTORY_SEPARATOR
. 'opt-in.tpl.php',
24 'class' => 'if-no-errors',
27 }, \Civi\Setup
::PRIORITY_PREPARE
);
29 // Second pass: Parse any settings that have been approved for use in this form.
30 \Civi\Setup
::dispatcher()
31 ->addListener('civi.setupui.boot', function (\Civi\Setup\UI\Event\UIBootEvent
$e) {
32 if (!$e->getCtrl()->blocks
['opt-in']['is_active']) {
36 \Civi\Setup
::log()->info(sprintf('[%s] Parse inputs', basename(__FILE__
)));
37 $values = $e->getField('opt-in', array());
38 $e->getModel()->extras
['opt-in']['empoweredBy'] = !empty($values['empoweredBy']);
39 $e->getModel()->extras
['opt-in']['versionCheck'] = !empty($values['versionCheck']);
41 // echo '<pre>'; print_r(['model'=> $e->getModel()->getValues(), 'v'=>$values]); echo '</pre>';
43 }, \Civi\Setup
::PRIORITY_LATE
);
45 \Civi\Setup
::dispatcher()
46 ->addListener('civi.setup.installDatabase', function (\Civi\Setup\Event\InstallDatabaseEvent
$e) {
49 if (isset($m->extras
['opt-in']['empoweredBy'])) {
50 \Civi\Setup
::log()->info(sprintf('[%s] Set empoweredBy', basename(__FILE__
)));
51 \Civi
::settings()->set('empoweredBy', (bool) $m->extras
['opt-in']['empoweredBy']);
54 if (isset($m->extras
['opt-in']['versionCheck'])) {
55 \Civi\Setup
::log()->info(sprintf('[%s] Set versionCheck', basename(__FILE__
)));
56 \CRM_Core_DAO
::executeQuery('UPDATE civicrm_job SET is_active = %1 WHERE api_entity LIKE "job" AND api_action LIKE "version_check"', array(
57 1 => array($m->extras
['opt-in']['versionCheck'] ?
1 : 0, 'Int'),
60 }, \Civi\Setup
::PRIORITY_LATE +
100);