public function ClamAVConfigForm::buildForm in ClamAV 8
Same name and namespace in other branches
- 2.x src/Form/ClamAVConfigForm.php \Drupal\clamav\Form\ClamAVConfigForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ ClamAVConfigForm.php, line 36
Class
- ClamAVConfigForm
- Configure file system settings for this site.
Namespace
Drupal\clamav\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('clamav.settings');
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Enable ClamAV integration'),
'#default_value' => $config
->get('enabled'),
);
$form['scan_mechanism_wrapper'] = array(
'#type' => 'details',
'#title' => $this
->t('Scan mechanism'),
'#open' => TRUE,
);
$form['scan_mechanism_wrapper']['scan_mode'] = array(
'#type' => 'radios',
'#title' => $this
->t('Scan mechanism'),
'#options' => array(
Config::MODE_EXECUTABLE => $this
->t('Executable'),
Config::MODE_DAEMON => $this
->t('Daemon mode (over TCP/IP)'),
Config::MODE_UNIX_SOCKET => $this
->t('Daemon mode (over Unix socket)'),
),
'#default_value' => $config
->get('scan_mode'),
'#description' => $this
->t("Control how Drupal connects to ClamAV.<br />Daemon mode is recommended if the ClamAV service is capable of running as a daemon."),
);
// Configuration if ClamAV is set to Executable mode.
$form['scan_mechanism_wrapper']['mode_executable'] = array(
'#type' => 'details',
'#title' => $this
->t('Executable mode configuration'),
'#open' => TRUE,
'#states' => array(
'visible' => array(
':input[name="scan_mode"]' => array(
'value' => Config::MODE_EXECUTABLE,
),
),
),
);
$form['scan_mechanism_wrapper']['mode_executable']['executable_path'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Executable path'),
'#default_value' => $config
->get('mode_executable.executable_path'),
'#maxlength' => 255,
);
$form['scan_mechanism_wrapper']['mode_executable']['executable_parameters'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Executable parameters'),
'#default_value' => $config
->get('mode_executable.executable_parameters') ?: '',
'#maxlength' => 255,
'#description' => $this
->t('Optional parameters to pass to the clamscan executable, e.g. %example.', array(
'%example' => '--max-recursion=10',
)),
);
// Configuration if ClamAV is set to Daemon mode.
$form['scan_mechanism_wrapper']['mode_daemon_tcpip'] = array(
'#type' => 'details',
'#title' => $this
->t('Daemon mode configuration (over TCP/IP)'),
'#open' => TRUE,
'#states' => array(
'visible' => array(
':input[name="scan_mode"]' => array(
'value' => Config::MODE_DAEMON,
),
),
),
);
$form['scan_mechanism_wrapper']['mode_daemon_tcpip']['hostname'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Hostname'),
'#default_value' => $config
->get('mode_daemon_tcpip.hostname'),
'#maxlength' => 255,
);
$form['scan_mechanism_wrapper']['mode_daemon_tcpip']['port'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Port'),
'#default_value' => $config
->get('mode_daemon_tcpip.port'),
'#size' => 6,
'#maxlength' => 8,
);
// Configuration if ClamAV is set to Daemon mode over Unix socket.
$form['scan_mechanism_wrapper']['mode_daemon_unixsocket'] = array(
'#type' => 'details',
'#title' => $this
->t('Daemon mode configuration (over Unix socket)'),
'#open' => TRUE,
'#states' => array(
'visible' => array(
':input[name="scan_mode"]' => array(
'value' => Config::MODE_UNIX_SOCKET,
),
),
),
);
$form['scan_mechanism_wrapper']['mode_daemon_unixsocket']['unixsocket'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Socket path'),
'#default_value' => $config
->get('mode_daemon_unixsocket.unixsocket'),
'#maxlength' => 255,
);
$form['outage_actions_wrapper'] = array(
'#type' => 'details',
'#title' => $this
->t('Outage behaviour'),
'#open' => TRUE,
);
$form['outage_actions_wrapper']['outage_action'] = array(
'#type' => 'radios',
'#title' => $this
->t('Behaviour when ClamAV is unavailable'),
'#options' => array(
Config::OUTAGE_BLOCK_UNCHECKED => $this
->t('Block unchecked files'),
Config::OUTAGE_ALLOW_UNCHECKED => $this
->t('Allow unchecked files'),
),
'#default_value' => $config
->get('outage_action'),
);
// Allow scanning according to scheme-wrapper.
$form['schemes'] = array(
'#type' => 'details',
'#title' => 'Scannable schemes / stream wrappers',
'#open' => TRUE,
'#description' => $this
->t('By default only @local schemes are scannable.', array(
'@local' => Link::fromTextAndUrl(t('local file-systems'), Url::fromUri('https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21StreamWrapper%21LocalStream.php/class/LocalStream/8.2.x'))
->toString(),
)),
);
$local_schemes = $this
->scheme_wrappers_available('local');
$remote_schemes = $this
->scheme_wrappers_available('remote');
if (count($local_schemes)) {
$form['schemes']['clamav_local_schemes'] = array(
'#type' => 'checkboxes',
'#title' => $this
->t('Local schemes'),
'#options' => $local_schemes,
'#default_value' => $this
->scheme_wrappers_to_scan('local'),
);
}
if (count($remote_schemes)) {
$form['schemes']['clamav_remote_schemes'] = array(
'#type' => 'checkboxes',
'#title' => $this
->t('Remote schemes'),
'#options' => $remote_schemes,
'#default_value' => $this
->scheme_wrappers_to_scan('remote'),
);
}
$form['verbosity_wrapper'] = array(
'#type' => 'details',
'#title' => $this
->t('Verbosity'),
'#open' => TRUE,
);
$form['verbosity_wrapper']['verbosity'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Verbose'),
'#description' => $this
->t('Verbose mode will log all scanned files, including files which pass the ClamAV scan.'),
'#default_value' => $config
->get('verbosity'),
);
return parent::buildForm($form, $form_state);
}