public function PhotosDirectoryImportForm::submitForm in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/Form/PhotosDirectoryImportForm.php \Drupal\photos\Form\PhotosDirectoryImportForm::submitForm()
- 8.4 src/Form/PhotosDirectoryImportForm.php \Drupal\photos\Form\PhotosDirectoryImportForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ PhotosDirectoryImportForm.php, line 188
Class
- PhotosDirectoryImportForm
- Defines a form to upload photos to this site.
Namespace
Drupal\photos\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('photos.settings');
$user_value = $form_state
->getValue('user');
$copy = $form_state
->getValue('copy');
if ($user_value) {
$form_state
->setRebuild();
}
else {
// @todo check if file is already in use before moving?
// - If in use copy?
$album = $form_state
->getValue('album');
$directory = $form_state
->getValue('directory');
if (file_exists($directory)) {
$nid = $album;
$album_uid = $form_state
->getValue('uid');
// If photos_access is enabled check viewid.
$scheme = 'default';
if ($this->moduleHandler
->moduleExists('photos_access')) {
$node = $this->entityTypeManager
->getStorage('node')
->load($nid);
if (isset($node->photos_privacy) && isset($node->photos_privacy['viewid'])) {
$album_viewid = $node->photos_privacy['viewid'];
if ($album_viewid > 0) {
// Check for private file path.
// @todo add support for other schemes?
if (PrivateStream::basePath()) {
$scheme = 'private';
}
else {
// Set warning message.
\Drupal::messenger()
->addWarning($this
->t('Warning: image
files can still be accessed by visiting the direct URL. For
better security, ask your website admin to setup a private
file path.'));
}
}
}
}
$account = $this->entityTypeManager
->getStorage('user')
->load($album_uid);
// Check if zip is included.
$allow_zip = $config
->get('photos_upzip') ? '|zip|ZIP' : '';
$file_extensions = 'png|PNG|jpg|JPG|jpeg|JPEG|gif|GIF' . $allow_zip;
$files = $this->fileSystem
->scanDirectory($directory, '/^.*\\.(' . $file_extensions . ')$/');
// Prepare batch.
$batch_args = [
$files,
$account,
$nid,
$scheme,
$copy,
];
$batch = [
'title' => $this
->t('Moving images to gallery'),
'operations' => [
[
'\\Drupal\\photos\\Form\\PhotosDirectoryImportForm::moveImageFiles',
$batch_args,
],
],
'finished' => '\\Drupal\\photos\\Form\\PhotosDirectoryImportForm::finishedMovingImageFiles',
];
batch_set($batch);
}
else {
\Drupal::messenger()
->addError($this
->t('Directory not found.'));
}
}
}