Skip to content

Commit 20d9e77

Browse files
committed
ACP2E-30: JSON code displayed for Recently view widget fixed
1 parent 2d44647 commit 20d9e77

File tree

1 file changed

+33
-7
lines changed
  • lib/internal/Magento/Framework/View/Element/UiComponent

1 file changed

+33
-7
lines changed

lib/internal/Magento/Framework/View/Element/UiComponent/Context.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,16 @@ protected function setAcceptType()
349349
{
350350
$this->acceptType = 'html';
351351

352-
$rawAcceptType = $this->request->getHeader('Accept');
353-
if (strpos($rawAcceptType, 'json') !== false) {
354-
$this->acceptType = 'json';
355-
} elseif (strpos($rawAcceptType, 'html') !== false) {
356-
$this->acceptType = 'html';
357-
} elseif (strpos($rawAcceptType, 'xml') !== false) {
358-
$this->acceptType = 'xml';
352+
$AcceptTypes = $this->getSortedAcceptHeader();
353+
foreach ($AcceptTypes as $key => $value) {
354+
if (strpos($key, 'json') !== false) {
355+
$this->acceptType = 'json';
356+
} elseif (strpos($key, 'html') !== false) {
357+
$this->acceptType = 'html';
358+
} elseif (strpos($key, 'xml') !== false) {
359+
$this->acceptType = 'xml';
360+
}
361+
break;
359362
}
360363
}
361364

@@ -408,4 +411,27 @@ public function getUiComponentFactory()
408411
{
409412
return $this->uiComponentFactory;
410413
}
414+
415+
/**
416+
* Returns sorted accept header based on q value
417+
*
418+
* @return array
419+
*/
420+
private function getSortedAcceptHeader()
421+
{
422+
$AcceptTypes = [];
423+
$rawAcceptType = $this->request->getHeader('Accept');
424+
$accept = explode(',', $rawAcceptType);
425+
foreach ($accept as $a) {
426+
// the default quality is 1.
427+
$q = 1;
428+
// check if there is a different quality
429+
if (strpos($a, ';q=') !== false) {
430+
list($a, $q) = explode(';q=', $a);
431+
}
432+
$AcceptTypes[$a] = $q;
433+
}
434+
arsort($AcceptTypes);
435+
return $AcceptTypes;
436+
}
411437
}

0 commit comments

Comments
 (0)