| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Declare backend actions/filters/shortcodes |
| 5 |
*/ |
| 6 |
|
| 7 |
/** |
| 8 |
* @var $app \FluentForm\Framework\Foundation\Application |
| 9 |
*/ |
| 10 |
|
| 11 |
// Add Entries Menu |
| 12 |
$app->addAction('ff_fluentform_form_application_view_entries', function ($form_id) use ($app) { |
| 13 |
(new \FluentForm\App\Modules\Entries\Entries())->renderEntries($form_id); |
| 14 |
}); |
| 15 |
|
| 16 |
$app->addAction('fluentform_after_form_navigation_editor', function ($form_id) use ($app) { |
| 17 |
(new \FluentForm\App\Modules\Registerer\Menu($app))->addPreviewButton($form_id); |
| 18 |
}); |
| 19 |
|
| 20 |
$app->addAction('media_buttons', function () { |
| 21 |
(new \FluentForm\App\Modules\EditorButtonModule())->addButton(); |
| 22 |
}); |
| 23 |
|
| 24 |
// On form submission register slack notifier |
| 25 |
use FluentForm\App\Services\Slack; |
| 26 |
|
| 27 |
$app->addAction( |
| 28 |
'fluentform_submission_inserted', |
| 29 |
function ($submissionId, $formData, $form) { |
| 30 |
Slack::notify($submissionId, $formData, $form); |
| 31 |
}, |
| 32 |
10, 3 |
| 33 |
); |
| 34 |
|
| 35 |
// On form submission register MailChimp subscriber. |
| 36 |
use FluentForm\App\Modules\Integration\MailChimpIntegration as MailChimp; |
| 37 |
|
| 38 |
$app->addAction( |
| 39 |
'fluentform_submission_inserted', |
| 40 |
function ($submissionId, $formData, $form) use ($app) { |
| 41 |
(new MailChimp($app))->subscribe($formData); |
| 42 |
}, |
| 43 |
10, 3 |
| 44 |
); |
| 45 |
|
| 46 |
$app->addAction('admin_init', function () { |
| 47 |
(new FluentForm\App\Modules\Track\TrackModule())->initTrack(); |
| 48 |
}); |
| 49 |
|
| 50 |
$app->addAction('admin_notices', function () { |
| 51 |
FluentForm\AdminNotice::showNotice(); |
| 52 |
}); |
| 53 |
|
| 54 |
/** |
| 55 |
* Register events to format the field values. |
| 56 |
* Response of the following elements' are |
| 57 |
* typically in array format and we just |
| 58 |
* need to concatenate it to a string. |
| 59 |
*/ |
| 60 |
$elements = [ |
| 61 |
'input_name', |
| 62 |
'select', |
| 63 |
'input_checkbox', |
| 64 |
'input_image', |
| 65 |
'input_file', |
| 66 |
'input_repeat', |
| 67 |
'address' |
| 68 |
]; |
| 69 |
|
| 70 |
foreach ($elements as $element) { |
| 71 |
$event = 'fluentform_response_render_'.$element; |
| 72 |
|
| 73 |
$app->addfilter($event, function ($response) { |
| 74 |
return \FluentForm\App\Modules\Form\FormDataParser::formatValue($response); |
| 75 |
}, 10, 1); |
| 76 |
} |
| 77 |
|