diff --git a/wire/core/Field.php b/wire/core/Field.php index 016d1fc3..91212a06 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -218,7 +218,7 @@ class Field extends WireData implements Saveable, Exportable { * * @param string $key Property name to set * @param mixed $value - * @return $this + * @return Field|WireData * */ public function set($key, $value) { @@ -810,8 +810,9 @@ class Field extends WireData implements Saveable, Exportable { $inputfield->attr('name', $this->name . $contextStr); $inputfield->set('label', $this->label); - // just in case an Inputfield needs to know it's Fieldtype context, or lack of it - $inputfield->set('hasFieldtype', $this->type); + // just in case an Inputfield needs to know its Fieldtype/Field context, or lack of it + $inputfield->set('hasFieldtype', $this->type); + $inputfield->set('hasField', $this); // custom field settings foreach($this->data as $key => $value) { diff --git a/wire/core/Inputfield.php b/wire/core/Inputfield.php index 358843e4..9c6f553c 100644 --- a/wire/core/Inputfield.php +++ b/wire/core/Inputfield.php @@ -68,6 +68,7 @@ * @property string $requiredIf Optional conditions under which input is required (selector string). #pw-group-behavior * @property InputfieldWrapper|null $parent The parent InputfieldWrapper for this Inputfield or null if not set. #pw-internal * @property null|bool|Fieldtype $hasFieldtype The Fieldtype using this Inputfield, or boolean false when known not to have a Fieldtype, or null when not known. #pw-group-other + * @property null|Field $hasField The Field object associated with this Inputfield, or or null when not applicable or not known. #pw-group-other * @property bool|null $useLanguages When multi-language support active, can be set to true to make it provide inputs for each language, where supported (default=false). #pw-group-behavior * @property null|bool|int $entityEncodeLabel Set to boolean false to specifically disable entity encoding of field header/label (default=true). #pw-group-output * @property null|bool $entityEncodeText Set to boolean false to specifically disable entity encoding for other text: description, notes, etc. (default=true). #pw-group-output diff --git a/wire/core/WireMarkupRegions.php b/wire/core/WireMarkupRegions.php index fa1f6e0c..a489d081 100644 --- a/wire/core/WireMarkupRegions.php +++ b/wire/core/WireMarkupRegions.php @@ -17,6 +17,12 @@ class WireMarkupRegions extends Wire { * */ const debug = false; + + /** + * @var array + * + */ + protected $debugNotes = array(); /** * HTML tag names that require no closing tag @@ -87,7 +93,11 @@ class WireMarkupRegions extends Wire { $findTag = $selectorInfo['findTag']; $hasClass = $selectorInfo['hasClass']; $regions = array(); - $removeMarkups = array(); + $_markup = self::debug ? $markup : ''; + + if(self::debug) { + $options['debugNote'] = (empty($options['debugNote']) ? "" : "$options[debugNote] => ") . "find($selector)"; + } // strip out comments if markup isn't required to stay the same if(!$options['exact']) $markup = $this->stripRegions('"; @@ -1153,7 +1189,8 @@ class WireMarkupRegions extends Wire { } else if($this->hasRegions($htmlRegions)) { $regions = $this->find(".pw-*, id=", $htmlRegions, array( 'verbose' => true, - 'leftover' => true + 'leftover' => true, + 'debugNote' => (isset($options['debugNote']) ? "$options[debugNote] => " : "") . "populate($callQty)", )); $leftoverMarkup = trim($regions["leftover"]); unset($regions["leftover"]); @@ -1178,7 +1215,7 @@ class WireMarkupRegions extends Wire { if(empty($region['action'])) $region['action'] = 'auto'; // replace if(empty($region['actionTarget'])) $region['actionTarget'] = $region['pwid']; // replace - $xregion = $region; + // $xregion = $region; $action = $region['action']; $actionTarget = $region['actionTarget']; $regionHTML = $region['region']; @@ -1203,15 +1240,20 @@ class WireMarkupRegions extends Wire { $debugAction = $region['action']; if($debugAction == 'auto') $debugAction = $isNew ? 'insert' : 'replace'; if($debugAction == 'replace' && empty($region['close'])) $debugAction = 'attr-update'; - $debugBytes = strlen($region['region']); $pwid = empty($region['pwid']) ? $region['actionTarget'] : $region['pwid']; $open = $region['open']; $openLen = strlen($open); - if($openLen > 50) $open = substr($open, 0, 50) . '[small]... +' . ($openLen-50) . ' bytes[/small]>'; - + if($openLen > 50) $open = substr($open, 0, 30) . '[sm]... +' . ($openLen - 30) . ' bytes[/sm]>'; + $debugRegionStart = substr($region['region'], 0, 50); + $pos = strrpos($debugRegionStart, '>'); + if($pos) $debugRegionStart = substr($debugRegionStart, 0, $pos+1); + $debugRegionEnd = substr($region['region'], -30); + $pos = strpos($debugRegionEnd, ''); + if($pos !== false) $debugRegionEnd = substr($debugRegionEnd, $pos); + $debugRegion = $this->debugNoteStr("$debugRegionStart ... $debugRegionEnd"); $region['note'] = "$debugAction => #$pwid " . ($region['actionTarget'] != $pwid ? "(target=$region[actionTarget])" : "") . - "... $open" . ($region['close'] ? "[small]$debugBytes bytes[/small]$region[close]" : ""); + "... $open" . ($region['close'] ? "[sm]{$debugRegion}[/sm]$region[close]" : ""); $regionNote = "$regionKey. $region[note]"; } else { $regionNote = ''; @@ -1224,7 +1266,6 @@ class WireMarkupRegions extends Wire { } else { // update the markup - //echo "
UPDATE('#$actionTarget', " . htmlentities($regionHTML) . ", mergeAttr=" . print_r($mergeAttr, true) . ""; $updates[] = array( 'actionTarget' => "#$actionTarget", 'regionHTML' => $regionHTML, @@ -1252,21 +1293,22 @@ class WireMarkupRegions extends Wire { if($debug) { $bull = "\n"; - $n = $recursionLevel; $leftoverBytes = strlen($leftoverMarkup); $debugNotes = ""; // "\nProcessWire markup regions debug #$n "; if(count($populatedNotes)) $debugNotes .= $bull . implode($bull, $populatedNotes); if(count($rejectedNotes)) $debugNotes .= "\nSKIPPED: $bull" . implode($bull, $rejectedNotes); - if($leftoverBytes) $debugNotes .= "\n $leftoverBytes non-region bytes skipped: $leftoverMarkup"; - $debugNotes .= "\n[small]" . Debug::timer($debugTimer) . " seconds[/small]"; - if(strpos($htmlDocument, $debugLandmark) !== false) { - $debugNotes = $this->wire('sanitizer')->entities($debugNotes); - $debugNotes = str_replace(array('[small]', '[/small]'), array('', ''), $debugNotes); - $debugNotes = "
$debugNotes$debugLandmark"; - $htmlDocument = str_replace($debugLandmark, $debugNotes, $htmlDocument); - } else { - $htmlDocument .= ""; + if($leftoverBytes) $debugNotes .= "\n $leftoverBytes non-region bytes skipped: [sm]{$leftoverMarkup}[/sm]"; + if(count($this->debugNotes)) { + $debugNotes .= "\n---------------"; + foreach($this->debugNotes as $n => $s) { + $debugNotes .= "\n$n. " . $this->debugNoteStr($s); + } } + $debugNotes = $this->wire('sanitizer')->entities($debugNotes); + $debugNotes .= "\n[sm]" . Debug::timer($debugTimer) . " seconds[/sm]"; + $debugNotes = str_replace(array('[sm]', '[/sm]'), array('', ''), $debugNotes); + $debugNotes = "
$debugNotes$debugLandmark"; + $htmlDocument = str_replace($debugLandmark, $debugNotes, $htmlDocument); } else if($hasDebugLandmark) { $htmlDocument = str_replace($debugLandmark, '', $htmlDocument); } @@ -1296,6 +1338,12 @@ class WireMarkupRegions extends Wire { if(strpos($html, ' id=') === false && strpos($html, 'pw-') === false) return false; return true; } - + + protected function debugNoteStr($str, $maxLength = 0) { + $str = str_replace(array("\r", "\n", "\t"), ' ', $str); + while(strpos($str, ' ') !== false) $str= str_replace(' ', ' ', $str); + if($maxLength) $str = substr($str, 0, $maxLength); + return trim($str); + } } \ No newline at end of file