N°3750 data-input-type : change XHR detection method

I added WebPage::IsAjaxPage, but this wasn't a good idea as XHR isn't really related to the Page impl used !
Instead we're now using the new method \utils::IsXmlHttpRequest which is a copy of \Symfony\Component\HttpFoundation\Request::isXmlHttpRequest
Many thanks @Molkobain !
This commit is contained in:
Pierre Goiffon
2021-03-02 11:54:15 +01:00
parent a850d3b67c
commit 225c176f71
3 changed files with 16 additions and 11 deletions

View File

@@ -2452,7 +2452,7 @@ JS
// N°3750 refresh container data-input-type attribute if in an Ajax context
// indeed in such a case we're only returning the field value content and not the parent container, so we need to update it !
if (WebPage::IsAjaxPage($oPage)) {
if (utils::IsXmlHttpRequest()) {
$sHTMLValue .= <<<HTML
<script>
$("[data-input-id='$iId']").data("input-type", "$sInputType");

View File

@@ -189,16 +189,26 @@ class utils
{
$sSAPIName = php_sapi_name();
$sCleanName = strtolower(trim($sSAPIName));
if ($sCleanName == 'cli')
{
if ($sCleanName == 'cli') {
return true;
}
else
{
} else {
return false;
}
}
/**
* @return bool true if we're in an XHR query
* @see \Symfony\Component\HttpFoundation\Request::IsXmlHttpRequest
*/
public static function IsXmlHttpRequest()
{
$sXhrHeaderName = 'X-Requested-With';
$sXhrHeaderIndexName = 'HTTP_'.str_replace('-', '_', strtoupper($sXhrHeaderName));
$sXhrHeader = $_SERVER[$sXhrHeaderIndexName] ?? null;
return ('XMLHttpRequest' === $sXhrHeader);
}
protected static $bPageMode = null;
/**
* @var boolean[]

View File

@@ -1491,9 +1491,4 @@ EOD
{
return $this->sTemplateRelPath;
}
public static function IsAjaxPage(WebPage $oPage)
{
return ($oPage instanceof AjaxPage);
}
}