You are here

protected function OpignoActivityForm::renameFile in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Form/OpignoActivityForm.php \Drupal\opigno_module\Form\OpignoActivityForm::renameFile()

Change filename.

1 call to OpignoActivityForm::renameFile()
OpignoActivityForm::save in src/Form/OpignoActivityForm.php
Form submission handler for the 'save' action.

File

src/Form/OpignoActivityForm.php, line 310

Class

OpignoActivityForm
Form controller for Activity edit forms.

Namespace

Drupal\opigno_module\Form

Code

protected function renameFile(&$file) {
  if (!empty($file)) {
    $stream_wrapper = \Drupal::service('file_system')
      ->uriScheme($file
      ->getFileUri());
    $filename = $file
      ->getFilename();
    $filename_new = preg_replace('/[^a-zA-Z0-9-_\\.]/', '-', $filename);
    $file
      ->setFilename($filename_new);
    $file
      ->save();
    file_move($file, $stream_wrapper . '://' . $filename_new);
  }
}