You are here

public function PhotosUpload::cleanTitle in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/PhotosUpload.php \Drupal\photos\PhotosUpload::cleanTitle()

Rename file with random name.

Parameters

string $title: The file name.

Return value

string The new name.

Overrides PhotosUploadInterface::cleanTitle

1 call to PhotosUpload::cleanTitle()
PhotosUpload::saveImage in src/PhotosUpload.php
Attach image file to PhotosImage entity.

File

src/PhotosUpload.php, line 175

Class

PhotosUpload
Functions to help with uploading images to albums.

Namespace

Drupal\photos

Code

public function cleanTitle($title = '') {
  $config = $this->configFactory
    ->get('photos.settings');
  if ($config
    ->get('photos_clean_title')) {

    // Remove extension.
    $title = pathinfo($title, PATHINFO_FILENAME);

    // Replace dash and underscore with spaces.
    $title = preg_replace("/[\\-_]/", " ", $title);

    // Trim leading and trailing spaces.
    $title = trim($title);
  }
  return $title;
}