1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 10:15:28 +02:00

Add new Page::hasFile() method

This commit is contained in:
Ryan Cramer
2020-08-27 15:37:37 -04:00
parent 8dbff5c7bc
commit 853a5cc490

View File

@@ -4139,6 +4139,31 @@ class Page extends WireData implements \Countable, WireMatchable {
return PagefilesManager::hasFiles($this);
}
/**
* Does Page have given filename in its files directory?
*
* @param string $file File basename or verbose hash
* @param array $options
* - `getPathname` (bool): Get full path + filename when would otherwise return boolean true? (default=false)
* - `getPagefile` (bool): Get Pagefile object when would otherwise return boolean true? (default=false)
* @return bool|string
* @since 3.0.166
*
*/
public function hasFile($file, array $options = array()) {
$defaults = array(
'getPathname' => false,
'getPagefile' => false,
);
$file = basename($file);
$options = array_merge($defaults, $options);
$hasFile = PagefilesManager::hasFile($this, $file, $options['getPathname']);
if($hasFile && $options['getPagefile']) {
$hasFile = $this->wire()->fieldtypes->FieldtypeFile->getPagefile($this, $file);
}
return $hasFile;
}
/**
* Returns the path for files, creating it if it does not yet exist
*