-
Posts
369 -
Joined
Everything posted by hellomoto
-
This does not work: // Prevent textual input from changing, e.g., if '2020-00-01' is entered, erase $this->addHookAfter('InputfieldDatetime::processInput', function(HookEvent $event) { // Get the object the event occurred on, if needed $InputfieldDatetime = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $input = $event->arguments(0); $page = $return->hasPage; $fname = $InputfieldDatetime->attributes['name']; $val = $input[$fname]; // $old = $return->hasPage->$fname; // bd(date('Y-m-d', $old)); /* Your code here, perhaps modifying the return value */ $fmt = $page->getField($fname)->dateInputFormat; // bd($fmt); $new = date('Y-m-d', strtotime($val)); if ($val == $new) return; // bd($val, $new); $this->wire->error( sprintf("Skipping field `%s` date string input: '%s' (format='%s')", $page->getField($fname)->get('label|name'), $val, $fmt) ); $return->hasPage->$fname = ''; // clear value // Populate back return value, if you have modified it $event->return = $return; }); I guess it might be better hook sanitizeValue in the Fieldtype? Sorry I'm getting very confused. The $event->return->hasPage->$fname has worked in prior tests, but I'm also confused because initially that property is set to the old value.
-
Why does this hook require saving 2x before applying the updated return value? function hookAfter_processInput(HookEvent $event) { // Get values of arguments sent to hook (if needed) $input = $event->arguments(0); $page = $event->return->hasPage; /* Your code here, perhaps modifying the return value */ $fname = $event->object->attributes['name']; $field = wire('fields')->get($fname); if (is_null($field) || !in_array($field->id, $this->data['fields'])) return; $newvalue = $input->$fname; $existing = $event->return->hasPage->$fname; $ok = $this->validate_date($newvalue, $existing); if ($ok) return; else { // Invalid: $event->return->hasPage->$fname = ''; // need to save 2x to affect ?? // $page->of(false); $page->setAndSave($fname, '', ['noHooks' => true]); // nothing $this->error("Invalid date text input for field `".$page->getField($field)->get('label|name')."`: $newvalue"); } }
-
PW date fields allow date strings such as "2020-00-01", as allowed by strtotime PHP function, but they will change upon save, with no warning. This erases the value on 1st save if it would otherwise be changed, but if it's valid, erases on 2nd save: $this->addHookAfter('InputfieldDatetime::processInput', function(HookEvent $event) { // Get the object the event occurred on, if needed $InputfieldDatetime = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $input = $event->arguments(0); $fname = $InputfieldDatetime->attributes['name']; // 'dated'; $new = $input[$fname]; $old = $return->hasPage->$fname; /* Your code here, perhaps modifying the return value */ $return->hasPage->$fname = ''; // Populate back return value, if you have modified it $event->return = $return; });
-
I have a multisite PW setup with several websites on it already. I set up a new PW site separately, renamed the site directory, changed the config httpHosts, and added it to index.config.php. What could I be missing? If you can delete this post, please do, I forgot to create the host on the VM, sorry.
-
How to move pagefile to a different page via API?
hellomoto replied to hellomoto's topic in API & Templates
$np = new Page(); $np->of(false); $np->parent = $page->id; $np->template = $make; $np->title = 'tmp'; $np->addStatus('unpublished'); $np->save(); $np->uploaded->add($f); $np->title = $f->basename; $np->save(); $this->message('Uploaded to new page '.$np->id.': '.$np->title); $page->upload->delete($f); $page->save(['noHooks' => true]); works -
This did not work... $np = new Page(); $np->parent = $page; $np->template = 'upload'; $np->title = 'tmp'; $np->save(); $np->of(false); $np->uploaded->add($f); $np->title = $f->basename;//$t->description; $np->name = $sanitizer->name($np->title); $np->save(); $this->message('Uploaded to new page: '.$np->title); wire('pagefiles')->delete($f); Error: Call to a member function add() on null
-
Module: AIOM+ (All In One Minify) for CSS, LESS, JS and HTML
hellomoto replied to David Karich's topic in Modules/Plugins
Updating less.php got rid of the aforementioned LESS error though the fonts don't load anyway. Changed the JS method allowing for a second call to generate JS to be deferred: public static function JS($javascripts, $js2 = false) { // ------------------------------------------------------------------------ // Check if at least one file was passed. // ------------------------------------------------------------------------ if(empty($javascripts)) throw new WireException('There were no files specified to minimize.'); // Support passing of $config->scripts as argument which is of type FilenameArray if(($javascripts instanceof FilenameArray)) $javascripts = (array) $javascripts->getIterator(); // Convert to array // ------------------------------------------------------------------------ // Check if files exist and generating the cache file name based // on the last editing of the file. // ------------------------------------------------------------------------ $javascripts = is_array($javascripts) ? $javascripts : array($javascripts); $javascripts = self::_fileArray($javascripts, '.js'); $cacheFile = self::_getCacheName($javascripts, self::$jsCachePrefix . ($js2 ? '2' : ''), '.js'); -
Module: AIOM+ (All In One Minify) for CSS, LESS, JS and HTML
hellomoto replied to David Karich's topic in Modules/Plugins
In the document html head tag: if (!empty($jshead)) echo '<script src="'.\AIOM::JS($jshead).'"></script>'; if (!empty($jsfoot)) echo '<script src="'.\AIOM::JS($jsfoot).'" defer></script>'; ... both lines render the same file, containing only one of the files in the respective arrays (each array has one item, it only contains the 1st)? What am I doing wrong? Also, including @import google fonts begets the following error: PHP Warning: Trying to access array offset on value of type null in .../processwire/site/modules/AllInOneMinify/lib/Less/Less.php:5746 No error if I include the compiled CSS instead of LESS, but @import is used in the README examples? -
Selectors class object -- how to get string property?
hellomoto replied to hellomoto's topic in API & Templates
Okay thanks but why not just access via ->__toString()? -
Selectors class object -- how to get string property?
hellomoto replied to hellomoto's topic in API & Templates
Sorry, it's $selectors->__toString() -
I'm slowing down reading the one I'm on now.
-
https://processwire.com/api/ref/selectors/ Is it not possible to access the `string` property? `$selectors->count` works, and $selectors->getArray() works for items. How is the string accessed? I've tried ->getProperty('string'), and I don't remember what else... The class has a selectorStr property but it's protected?
-
I'm almost finished reading Developing Large Web Applications by Kyle Loudon (2010) and it keenly reminded me of ProcessWire, and I'd thought that PW came out around then but maybe earlier... Anyway the book is somewhat outdated by now, but I found it at the library and read through most of it quickly. It does provide a solid introduction to OOP in PHP; JavaScript has changed much more, and I basically skipped the CSS part. Are there any [maybe newer] books you would recommend?
-
I see here https://github.com/adminerevo/adminerevo/blob/6bb4d778cb2077889811727721253e14250eba8b/adminer/file.inc.php#L6 Do you know why the files are compressed?
-
https://github.com/adrianbj/TracyDebugger/commit/daf24456c5cbf09e8c27cfb59057bf632ae8bcad the lzw_decompress functions & special characters?
-
I just realized and then this was already in the Google SERP open from searching "wire in wire function processwire" regarding something else (wire('config') in a function was not a function because the namespace wasn't present): wire() in the init method of a module which extends ProcessPageAdd in a different PW instance that is instantiated in ready.php is initialized also in the instance instantiating the other instance. For example: wire()->addHookBefore("ProcessPageAdd::execute", $this, 'hookPageAdd'); resulted in an error adding a page of the same template name in the instance instantiating the other one. Prepending with $this-> disables the cross-site functionality.
-
Maybe it's Firefox looking for favicon file automatically... It goes away if I indicate a favicon... Indicating a nonexistent one changes the stack trace to load resource:///modules/FaviconLoader.jsm:180:20 load resource:///modules/FaviconLoader.jsm:567:70 loadIcons resource:///modules/FaviconLoader.jsm:645:26 FaviconLoader/this.iconTask< resource:///modules/FaviconLoader.jsm:621:18 _runTask resource://gre/modules/DeferredTask.sys.mjs:347:18 _timerCallback/< resource://gre/modules/DeferredTask.sys.mjs:318:20 _timerCallback resource://gre/modules/DeferredTask.sys.mjs:337:9 _startTimer/callback/< resource://gre/modules/DeferredTask.sys.mjs:185:18 Sorry this isn't quite insightful
-
I don't have a request in templates for favicon.ico. In Firefox inspector: Request cookies are: 'adminer_key', 'adminer_sid', 'tracy-session', 'wire0s', 'wire1s', 'wire1s_challenge', 'wires', 'wires_challenge'. Stack trace: load resource:///modules/FaviconLoader.jsm:180:20 load resource:///modules/FaviconLoader.jsm:567:70 loadIcons resource:///modules/FaviconLoader.jsm:645:26 onPageShow resource:///modules/FaviconLoader.jsm:679:12 onHeadParsed resource:///actors/LinkHandlerChild.sys.mjs:56:24 handleEvent resource:///actors/LinkHandlerChild.sys.mjs:172:21 I don't know what those are. I did recently install and then afterward notice an odd commit and deleted the module -- https://github.com/FriendsOfProcessWire/FieldtypeLeafletMapMarker/commit/e57e9373e6cccb79fe89dfda00fec117624649f2 has a bunch of empty files? "Remove executable bit from files"? -- Sorry I just realized the permissions changed from 755 to 644...
-
Cannot bootstrap index.php & run via PHP CLI?
hellomoto replied to hellomoto's topic in API & Templates
Wow I missed that thank you. The conditional inclusion is so as to not repeat if running from within PW already, only require if ran from outside PW. var_dump(class_exists('ProcessWire')); returns false from within it so that's why it's \Templates... -
Cannot bootstrap index.php & run via PHP CLI?
hellomoto replied to hellomoto's topic in API & Templates
Thanks it is installed? -
When I include index.php and run the script via command line `php bootstrap.php` this error is returned: PHP Warning: Cannot modify header information - headers already sent by (output started at /pw/bootstrap/index.php:5) in /pw/index.php on line 41 404 page not found (no site configuration or install.php available) I've tried moving the script around also and it's the same if external... <?php namespace ProcessWire; if (!class_exists('ProcessWire\Templates')) { // $pw_dir = dirname(dirname(__FILE__), 2); echo $pw_dir; $boot = "../pw/index.php"; $boot = realpath($boot); echo $boot; require_once $boot;// $pw_dir.'/index.php'; echo 'booted'; exit; } (so as to not include if ran from within PW instance, also tried with no condition)