You are here

function _file_prepare_directory in GoogleTagManager 8

Same name and namespace in other branches
  1. 7.2 google_tag.module \_file_prepare_directory()
  2. 7 includes/admin.inc \_file_prepare_directory()

Checks that the directory exists and is writable.

@todo Remove this function if core is updated to check the executable bit.

See also

file_prepare_directory()

2 calls to _file_prepare_directory()
ContainerManager::createAssets in src/Entity/ContainerManager.php
Prepares directory for and saves snippet files for a container.
google_tag_requirements in ./google_tag.install
Implements hook_requirements().

File

./google_tag.module, line 117
Provides primary Drupal hook implementations.

Code

function _file_prepare_directory(&$directory, $options = FileSystemInterface::MODIFY_PERMISSIONS) {
  $file_system = \Drupal::service('file_system');
  if (!\Drupal::service('stream_wrapper_manager')
    ->isValidScheme(StreamWrapperManager::getScheme($directory))) {

    // Only trim if we're not dealing with a stream.
    $directory = rtrim($directory, '/\\');
  }

  // Check if directory exists.
  if (!is_dir($directory)) {

    // Let mkdir() recursively create directories and use the default directory
    // permissions.
    if ($options & FileSystemInterface::CREATE_DIRECTORY) {
      return @$file_system
        ->mkdir($directory, NULL, TRUE);
    }
    return FALSE;
  }

  // The directory exists, so check to see if it is writable.
  $writable = _google_tag_is_writable($directory) && _google_tag_is_executable($directory);
  if (!$writable && $options & FileSystemInterface::MODIFY_PERMISSIONS) {
    return $file_system
      ->chmod($directory);
  }
  return $writable;
}