blacklist = array_merge($this->blacklist, $blacklist); } /** * Controls whether test directories will be scanned. * * @param bool $flag * Pass FALSE to skip all test directories in the discovery. If TRUE, * extensions in test directories will be discovered and only the global * directory blacklist in RecursiveExtensionFilterIterator::$blacklist is * applied. */ public function acceptTests($flag = FALSE) { $this->acceptTests = $flag; if (!$this->acceptTests) { $this->blacklist[] = 'tests'; } } /** * {@inheritdoc} */ public function getChildren() { $filter = parent::getChildren(); // Pass on the blacklist. $filter->blacklist = $this->blacklist; // Pass the $acceptTests flag forward to child iterators. $filter->acceptTests($this->acceptTests); return $filter; } /** * {@inheritdoc} */ public function accept() { $name = $this->current()->getFilename(); // FilesystemIterator::SKIP_DOTS only skips '.' and '..', but not hidden // directories (like '.git'). if ($name[0] == '.') { return FALSE; } if ($this->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 ($this->current()->getSubPath() == '') { return in_array($name, $this->whitelist, 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 substr($this->current()->getPathname(), -14) == 'modules/config'; } // Accept the directory unless the name is blacklisted. return !in_array($name, $this->blacklist, TRUE); } else { // Only accept extension info files. return substr($name, -9) == '.info.yml'; } } }