| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\Integrations\Slack; |
| 4 |
|
| 5 |
defined('ABSPATH') or die; |
| 6 |
|
| 7 |
use FluentForm\App\Helpers\Helper; |
| 8 |
use FluentForm\Framework\Foundation\Application; |
| 9 |
use FluentForm\Framework\Helpers\ArrayHelper as Arr; |
| 10 |
|
| 11 |
class SlackNotificationActions |
| 12 |
{ |
| 13 |
protected $app = null; |
| 14 |
|
| 15 |
public function __construct(Application $app) |
| 16 |
{ |
| 17 |
$this->app = $app; |
| 18 |
// add_filter('fluentform/notifying_async_slack', '__return_false'); |
| 19 |
} |
| 20 |
|
| 21 |
public function register() |
| 22 |
{ |
| 23 |
add_filter('fluentform/global_notification_active_types', function ($types) { |
| 24 |
$isEnabled = Helper::isSlackEnabled(); |
| 25 |
if ($isEnabled) { |
| 26 |
$types['slack'] = 'slack'; |
| 27 |
} |
| 28 |
return $types; |
| 29 |
}); |
| 30 |
add_action('fluentform/integration_notify_slack', [$this, 'notify'], 20, 4); |
| 31 |
add_filter('fluentform/get_meta_key_settings_response', function ($response, $formId, $key) { |
| 32 |
if ('slack' == $key) { |
| 33 |
$formApi = fluentFormApi()->form($formId); |
| 34 |
$response['formattedFields'] = array_values($formApi->labels()); |
| 35 |
} |
| 36 |
|
| 37 |
return $response; |
| 38 |
}, 10, 3); |
| 39 |
} |
| 40 |
|
| 41 |
public function notify($feed, $formData, $entry, $form) |
| 42 |
{ |
| 43 |
$isEnabled = Helper::isSlackEnabled(); |
| 44 |
if (! $isEnabled) { |
| 45 |
return; |
| 46 |
} |
| 47 |
$response = Slack::handle($feed, $formData, $form, $entry); |
| 48 |
if ('success' === Arr::get($response, 'status')) { |
| 49 |
do_action('fluentform/integration_action_result', $feed, 'success', |
| 50 |
__('Slack feed has been successfully initialed and pushed data', 'fluentform')); |
| 51 |
} else { |
| 52 |
$error = Arr::get($response, 'message'); |
| 53 |
do_action('fluentform/integration_action_result', $feed, 'failed', $error); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|