mirror of
https://github.com/processwire/processwire.git
synced 2025-08-20 21:42:23 +02:00
Fix issue where ajax-loaded Inputfield render() didn't have before(render) hooks called when rendering the non-ajax placeholder, which was identified in processwire/processwire-issues#480
This commit is contained in:
@@ -709,23 +709,8 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
|||||||
return $this->renderInputfield($in, $renderValueMode);
|
return $this->renderInputfield($in, $renderValueMode);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// do not render ajax inputfield
|
// do not render ajax inputfield now, instead render placeholder
|
||||||
$url = $this->wire('input')->url();
|
return $this->renderInputfieldAjaxPlaceholder($inputfield, $renderValueMode);
|
||||||
$queryString = $this->wire('input')->queryString();
|
|
||||||
if(strpos($queryString, 'renderInputfieldAjax=') !== false) {
|
|
||||||
// in case nested ajax request
|
|
||||||
$queryString = preg_replace('/&?renderInputfieldAjax=[^&]+/', '', $queryString);
|
|
||||||
}
|
|
||||||
$url .= $queryString ? "?$queryString&" : "?";
|
|
||||||
$url .= "renderInputfieldAjax=$inputfieldID";
|
|
||||||
$out = "<div class='renderInputfieldAjax'><input type='hidden' value='$url' /></div>";
|
|
||||||
if($inputfield instanceof InputfieldWrapper) {
|
|
||||||
// load assets they will need
|
|
||||||
foreach($inputfield->getAll() as $in) {
|
|
||||||
$in->renderReady($inputfield, $renderValueMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $out;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,6 +727,45 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a placeholder for an ajax-loaded Inputfield
|
||||||
|
*
|
||||||
|
* @param Inputfield $inputfield
|
||||||
|
* @param bool $renderValueMode
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function renderInputfieldAjaxPlaceholder(Inputfield $inputfield, $renderValueMode) {
|
||||||
|
|
||||||
|
$inputfieldID = $inputfield->attr('id');
|
||||||
|
$url = $this->wire('input')->url();
|
||||||
|
$queryString = $this->wire('input')->queryString();
|
||||||
|
|
||||||
|
if(strpos($queryString, 'renderInputfieldAjax=') !== false) {
|
||||||
|
// in case nested ajax request
|
||||||
|
$queryString = preg_replace('/&?renderInputfieldAjax=[^&]+/', '', $queryString);
|
||||||
|
}
|
||||||
|
|
||||||
|
$url .= $queryString ? "?$queryString&" : "?";
|
||||||
|
$url .= "renderInputfieldAjax=$inputfieldID";
|
||||||
|
|
||||||
|
$out = "<div class='renderInputfieldAjax'><input type='hidden' value='$url' /></div>";
|
||||||
|
|
||||||
|
if($inputfield instanceof InputfieldWrapper) {
|
||||||
|
// load assets they will need
|
||||||
|
foreach($inputfield->getAll() as $in) {
|
||||||
|
$in->renderReady($inputfield, $renderValueMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure that Inputfield::render() hooks are still called
|
||||||
|
if($inputfield->hasHook('render()')) {
|
||||||
|
$inputfield->runHooks('render', array(), 'before');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process input for all children
|
* Process input for all children
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user