From 5a283e91bbd635200c2c1f6defc382c9c7b16a0c Mon Sep 17 00:00:00 2001 From: Netcarver Date: Mon, 10 Oct 2016 16:37:30 +0100 Subject: [PATCH 1/3] Add selectors and results to module log. --- ProcessSelectorTest.module | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ProcessSelectorTest.module b/ProcessSelectorTest.module index 2dab801..b624db1 100644 --- a/ProcessSelectorTest.module +++ b/ProcessSelectorTest.module @@ -142,6 +142,11 @@ class ProcessSelectorTest extends Process { */ public function ___execute() { + $info = array( + 'selector' => '', + 'results' => false, + ); + // save selector and limit to session // (don't want to use GET parameters for selector string anyway) $this->saveFormValuesToSession(); @@ -153,6 +158,7 @@ class ProcessSelectorTest extends Process { // --> validation errors are supposed to arise at this point (errors are catched and displayed) try { $selector = wire('session')->get('selectortest_selector'); + $info['selector'] = $selector; // ..well, almost as-is: add limit if specified // ..and with limit + pagination additional offset may be added while building the query (at core, that is) @@ -175,6 +181,7 @@ class ProcessSelectorTest extends Process { // generate the results table $cnt = $results->getTotal(); $this->view->resultCount = $cnt; + $info['results'] = $cnt; $initialData = array(); if($cnt) { // pager, if needed @@ -226,11 +233,30 @@ class ProcessSelectorTest extends Process { } catch (WireException $e) { // did not succeed, show error message to the user $this->error($e->getMessage()); + $info['results'] = $e->getMessage(); } + $this->logResults($info); return $this->view->render(); } + + /** + * Adds the results to the log file... + */ + protected function logResults($info) { + //if (0 === $info['results']) return; // Don't log selectors that return nothing. + if (false === $info['results']) { + $res = 'SELECTOR ERROR'; + } elseif (is_string($info['results'])) { + $res = 'Error: ' . $this->sanitizer->text($info['results']); + } else { + $res = $info['results'].' pages'; + } + $this->log("'{$info['selector']}' ⇒ $res"); + } + + /** * Save submitted values, or default values, to session. * This way values may be more complex than is suitable for get-variables From 6415b60d22fb4e9f4c43a632a3c74b17a92d4d26 Mon Sep 17 00:00:00 2001 From: Netcarver Date: Mon, 10 Oct 2016 16:38:05 +0100 Subject: [PATCH 2/3] Add hook allowing custom formatting of repeater titles in results view --- ProcessSelectorTest.module | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ProcessSelectorTest.module b/ProcessSelectorTest.module index b624db1..b4e1b43 100644 --- a/ProcessSelectorTest.module +++ b/ProcessSelectorTest.module @@ -591,7 +591,9 @@ class ProcessSelectorTest extends Process { // (placeholders, visible here because of output formatting being intentionally off) if($r->status & Page::statusUnpublished) continue; // label as a string to get 0 displayed as well - $children[] = array('label' => (string)$n++, 'children' => $this->getPageFieldValues($r)); + $replabel = $this->formatRepeaterLabel($field, $r, $n); + $children[] = array('label' => $replabel, 'children' => $this->getPageFieldValues($r)); + $n++; } $item['value'] = count($children); break; @@ -601,6 +603,18 @@ class ProcessSelectorTest extends Process { return $item; } + + /** + * Hook to format the label of repeater fields. + * + * Add an after hook to this event if you want to do some custom formatting for some of your repeater fields. + */ + protected function ___formatRepeaterLabel($parent_field, $r, $n) { + $replabel = (string)$n; + if ($r->title) $replabel .= ' ' . $r->title; + return $replabel; + } + /** * Get properties of a page * From ae5c47de74fc07d684ad60ee7debdbf515243d4a Mon Sep 17 00:00:00 2001 From: Michael Bolli Date: Fri, 28 Jun 2019 15:29:33 +0200 Subject: [PATCH 3/3] make the module compatible with ProcessWire 3.* --- ProcessSelectorTest.module | 9 +++++++++ view.php | 3 +++ 2 files changed, 12 insertions(+) diff --git a/ProcessSelectorTest.module b/ProcessSelectorTest.module index b4e1b43..8c0bd30 100644 --- a/ProcessSelectorTest.module +++ b/ProcessSelectorTest.module @@ -1,5 +1,14 @@