mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 03:05:26 +02:00
Add new Page::hasFile() method
This commit is contained in:
@@ -4139,6 +4139,31 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
return PagefilesManager::hasFiles($this);
|
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
|
* Returns the path for files, creating it if it does not yet exist
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user