mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +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:
@@ -1248,8 +1248,12 @@ class WireMarkupRegions extends Wire {
|
|||||||
$attrs = $region['attrs'];
|
$attrs = $region['attrs'];
|
||||||
$attrStr = count($attrs) ? ' ' . $this->renderAttributes($attrs, false) : '';
|
$attrStr = count($attrs) ? ' ' . $this->renderAttributes($attrs, false) : '';
|
||||||
if(!strlen(trim($attrStr))) $attrStr = '';
|
if(!strlen(trim($attrStr))) $attrStr = '';
|
||||||
|
if($region['actionType'] == 'bool') {
|
||||||
|
$regionHTML = $region['region'];
|
||||||
|
} else {
|
||||||
$regionHTML = str_replace($region['open'], "<$region[name]$attrStr>", $regionHTML);
|
$regionHTML = str_replace($region['open'], "<$region[name]$attrStr>", $regionHTML);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($debug) {
|
if($debug) {
|
||||||
$debugAction = $region['action'];
|
$debugAction = $region['action'];
|
||||||
@@ -1333,6 +1337,8 @@ class WireMarkupRegions extends Wire {
|
|||||||
$numUpdates += $this->populate($htmlDocument, $xregions);
|
$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 there is any leftover markup, place it above the HTML where it would usually go
|
||||||
if(strlen($leftoverMarkup)) {
|
if(strlen($leftoverMarkup)) {
|
||||||
$htmlDocument = $leftoverMarkup . $htmlDocument;
|
$htmlDocument = $leftoverMarkup . $htmlDocument;
|
||||||
@@ -1342,6 +1348,20 @@ class WireMarkupRegions extends Wire {
|
|||||||
return $numUpdates;
|
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?
|
* Is the given HTML markup likely to have regions?
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user