1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Updates related to WireMarkupRegions discussion in issue processwire/processwire-issues#195 - fix behavior of boolean pw-before/pw-after attributes, and add support for <pw-region> or <region> tags.

This commit is contained in:
Ryan Cramer
2017-03-15 14:04:49 -04:00
parent 11ebcfb456
commit 770c717baa

View File

@@ -1248,8 +1248,12 @@ class WireMarkupRegions extends Wire {
$attrs = $region['attrs'];
$attrStr = count($attrs) ? ' ' . $this->renderAttributes($attrs, false) : '';
if(!strlen(trim($attrStr))) $attrStr = '';
if($region['actionType'] == 'bool') {
$regionHTML = $region['region'];
} else {
$regionHTML = str_replace($region['open'], "<$region[name]$attrStr>", $regionHTML);
}
}
if($debug) {
$debugAction = $region['action'];
@@ -1333,6 +1337,8 @@ class WireMarkupRegions extends Wire {
$numUpdates += $this->populate($htmlDocument, $xregions);
}
if($this->removeRegionTags($htmlDocument)) $numUpdates++;
// if there is any leftover markup, place it above the HTML where it would usually go
if(strlen($leftoverMarkup)) {
$htmlDocument = $leftoverMarkup . $htmlDocument;
@@ -1342,6 +1348,20 @@ class WireMarkupRegions extends Wire {
return $numUpdates;
}
/**
* Remove any <region> or <pw-region> tags present in the markup, leaving their innerHTML contents
*
* @param string $html
* @return bool True if tags were removed, false if not
*
*/
protected function removeRegionTags(&$html) {
if(stripos($html, '</region>') === false && strpos($html, '</pw-region>') === false) return false;
$html = preg_replace('!</?(?:region|pw-region)(?:\s[^>]*>|>)!i', '', $html);
//$html = str_ireplace(array('</region>', '</pw-region>'), '', $html);
return true;
}
/**
* Is the given HTML markup likely to have regions?
*