From 853a5cc4900bd73f00880b01ddc431ae707d9154 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 27 Aug 2020 15:37:37 -0400 Subject: [PATCH] Add new Page::hasFile() method --- wire/core/Page.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/wire/core/Page.php b/wire/core/Page.php index 7dc8593e..203da297 100644 --- a/wire/core/Page.php +++ b/wire/core/Page.php @@ -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 *