You are here

function photos_access_move_files_form_submit in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos_access/photos_access.module \photos_access_move_files_form_submit()
  2. 6.0.x photos_access/photos_access.module \photos_access_move_files_form_submit()

Form submission handler for private file management.

See also

photos_access_form_node_form_alter()

1 string reference to 'photos_access_move_files_form_submit'
photos_access_form_node_form_alter in photos_access/photos_access.module
Implements hook_form_BASE_FORM_ID_alter() for form_node.

File

photos_access/photos_access.module, line 199
Implementation of photos_access.module.

Code

function photos_access_move_files_form_submit(&$form, FormStateInterface $form_state) {
  $node = $form_state
    ->getFormObject()
    ->getEntity();

  // Check privacy settings.
  $privacy = $form_state
    ->getValue('privacy');
  $public = FALSE;
  if (isset($privacy['viewid']) && $privacy['viewid'] == 0) {

    // Gallery is open, move files to public.
    $public = TRUE;
  }

  // Check for private file path.
  if (PrivateStream::basePath()) {

    // Move files if needed.
    // @todo Batch API.
    photos_access_move_files($node, $public);
  }
  else {
    if (!$public) {

      // Set warning message.
      \Drupal::messenger()
        ->addWarning(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.'));
    }
  }
}