From 94e71209b348335b9ceeb44219c72c94723be554 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 5 Mar 2021 15:12:06 -0500 Subject: [PATCH] Update HookEvent class to support named arguments directly from $event object --- wire/core/HookEvent.php | 20 ++++++++++++++++++- .../InputfieldFile/InputfieldFile.module | 4 ++++ ...ocessPageEdit.css => ProcessPageEdit.scss} | 0 3 files changed, 23 insertions(+), 1 deletion(-) rename wire/modules/Process/ProcessPageEdit/{ProcessPageEdit.css => ProcessPageEdit.scss} (100%) diff --git a/wire/core/HookEvent.php b/wire/core/HookEvent.php index 91874e4d..7cea54e3 100644 --- a/wire/core/HookEvent.php +++ b/wire/core/HookEvent.php @@ -119,8 +119,10 @@ class HookEvent extends WireData { */ public function argumentsByName($n = '') { - $names = $this->getArgumentNames(); $arguments = $this->arguments(); + if(isset($arguments[$n])) return $arguments[$n]; + + $names = $this->getArgumentNames(); if($n) { $key = array_search($n, $names); @@ -222,6 +224,22 @@ class HookEvent extends WireData { } } + /** + * Get + * + * @param object|string $key + * @return mixed|null + * + */ + public function get($key) { + $value = parent::get($key); + if($value === null && !ctype_digit("$key") && array_key_exists($key, $this->data['arguments'])) { + // allow named arguments to be accessed from get() + $value = $this->data['arguments'][$key]; + } + return $value; + } + /** * Return a string representing the HookEvent * diff --git a/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module b/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module index 52c64424..34d3fc08 100644 --- a/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module +++ b/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module @@ -264,6 +264,10 @@ class InputfieldFile extends Inputfield implements InputfieldItemList, Inputfiel // if given a Pagefile rather than a Pagefiles, use the Pagefiles instead $value = $value->pagefiles; } + if($value instanceof Pagefiles) { + $page = $value->page; + if($page && $page->template->noLang) $this->noLang = true; + } } return parent::setAttribute($key, $value); } diff --git a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.css b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.scss similarity index 100% rename from wire/modules/Process/ProcessPageEdit/ProcessPageEdit.css rename to wire/modules/Process/ProcessPageEdit/ProcessPageEdit.scss