function RecursiveExtensionFilterCallback::accept

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Extension/Discovery/RecursiveExtensionFilterCallback.php \Drupal\Core\Extension\Discovery\RecursiveExtensionFilterCallback::accept()

Checks whether a given filesystem directory is acceptable.

Parameters

\RecursiveDirectoryIterator $filesystem_directory: The filesystem directory to check.

Return value

bool TRUE if the given filesystem directory is acceptable, otherwise FALSE.

File

core/lib/Drupal/Core/Extension/Discovery/RecursiveExtensionFilterCallback.php, line 105

Class

RecursiveExtensionFilterCallback
Filters a RecursiveDirectoryIterator to discover extensions.

Namespace

Drupal\Core\Extension\Discovery

Code

public function accept(\RecursiveDirectoryIterator $filesystem_directory) : bool {
  $name = $filesystem_directory->getFilename();
  // FilesystemIterator::SKIP_DOTS only skips '.' and '..', but not hidden
  // directories (like '.git').
  if ($name[0] === '.') {
    return FALSE;
  }
  if ($filesystem_directory->isDir()) {
    // If this is a subdirectory of a base search path, only recurse into the
    // fixed list of expected extension type directory names. Required for
    // scanning the top-level/root directory; without this condition, we would
    // recurse into the whole filesystem tree that possibly contains other
    // files aside from Drupal.
    if ($filesystem_directory->getSubPath() === '') {
      return in_array($name, $this->allowedExtensionTypes, TRUE);
    }
    // 'config' directories are special-cased here, because every extension
    // contains one. However, those default configuration directories cannot
    // contain extensions. The directory name cannot be globally skipped,
    // because core happens to have a directory of an actual module that is
    // named 'config'. By explicitly testing for that case, we can skip all
    // other config directories, and at the same time, still allow the core
    // config module to be overridden/replaced in a profile/site directory
    // (whereas it must be located directly in a modules directory).
    if ($name === 'config') {
      return str_ends_with($filesystem_directory->getPathname(), 'modules/config');
    }
    // Accept the directory unless the folder is skipped.
    return !in_array($name, $this->skippedFolders, TRUE);
  }
  // Only accept extension info files.
  return str_ends_with($name, '.info.yml');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.