Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Commit

Permalink
Issue #2671914: Implement EB configuration UI
Browse files Browse the repository at this point in the history
  • Loading branch information
primsi committed Mar 15, 2016
1 parent 292ea5e commit 4de14e8
Showing 1 changed file with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,73 @@ protected function validateExtension($filename, $extensions) {
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$configuration = $this->getConfiguration();
$settings = $configuration['settings'];
$form += parent::buildConfigurationForm($form, $form_state);
$configuration = $this->configuration;

$form['upload_location'] = [
'#type' => 'textfield',
'#title' => $this->t('Upload location'),
'#default_value' => $configuration['upload_location'],
];

$form['dropzone_description'] = [
'#type' => 'textfield',
'#title' => $this->t('Dropzone drag-n-drop zone text'),
'#default_value' => $settings['dropzone_description'],
'#default_value' => $configuration['dropzone_description'],
];

preg_match('%[\d\.]%', $configuration['max_filesize'], $matches);
$max_filesize = !empty($matches) ? array_shift($matches) : '1';

$form['max_filesize'] = [
'#type' => 'number',
'#title' => $this->t('Maximum size of files'),
'#min' => '0',
'#field_suffix' => $this->t('MB'),
'#default_value' => $max_filesize,
];

$form['extensions'] = [
'#type' => 'textfield',
'#title' => $this->t('Allowed file extensions'),
'#desciption' => $this->t('A space separated list of file extensions'),
'#default_value' => $configuration['extensions'],
];

return $form;
}

/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues()['table'][$this->uuid()]['form'];

if (!empty($values['extensions'])) {
$extensions = explode(' ', $values['extensions']);
$fail = FALSE;

foreach ($extensions as $extension) {
if (preg_match('%^\w*$%', $extension) !== 1) {
$fail = TRUE;
}
}

if ($fail) {
$form_state->setErrorByName('extensions', $this->t('Invalid extension list format.'));
}
}
}

/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues()['table'][$this->uuid()]['form'];

if (!empty($values['max_filesize'])) {
$this->configuration['max_filesize'] = $values['max_filesize'] . 'M';
}
}


}

0 comments on commit 4de14e8

Please sign in to comment.