mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +02:00
Fix issue processwire/processwire-issues#1436 where $pages->findJoin() used on file/image fields was resulting in them being blank in returned pages
This commit is contained in:
@@ -345,12 +345,18 @@ class PageFinder extends Wire {
|
||||
protected $reverseAfter = false;
|
||||
|
||||
/**
|
||||
* Data that should be populated back to any resulting PageArray’s data() method
|
||||
* Data that should be conditionally populated back to any resulting PageArray’s data() method
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
*/
|
||||
protected $pageArrayData = array();
|
||||
protected $pageArrayData = array(
|
||||
/* may include:
|
||||
'fields' => array()
|
||||
'extends' => array()
|
||||
'joinFields' => array()
|
||||
*/
|
||||
);
|
||||
|
||||
/**
|
||||
* The fully parsed/final selectors used in the last find() operation
|
||||
@@ -1670,13 +1676,19 @@ class PageFinder extends Wire {
|
||||
$query->leftjoin('pages_paths ON pages_paths.pages_id=pages.id');
|
||||
}
|
||||
if(!empty($opts['joinFields'])) {
|
||||
$this->pageArrayData['joinFields'] = array(); // identify whether each field supported autojoin
|
||||
foreach($opts['joinFields'] as $joinField) {
|
||||
$joinField = $this->fields->get($joinField);
|
||||
if(!$joinField || !$joinField instanceof Field) continue;
|
||||
$joinTable = $database->escapeTable($joinField->getTable());
|
||||
if(!$joinTable || !$joinField->type) continue;
|
||||
if(!$joinField->type->getLoadQueryAutojoin($joinField, $query)) continue;
|
||||
if($joinField->type->getLoadQueryAutojoin($joinField, $query)) {
|
||||
$autojoinTables[$joinTable] = $joinTable; // added at end if not already joined
|
||||
$this->pageArrayData['joinFields'][$joinField->name] = true;
|
||||
} else {
|
||||
// fieldtype does not support autojoin
|
||||
$this->pageArrayData['joinFields'][$joinField->name] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if($options['returnVerbose']) {
|
||||
|
@@ -609,6 +609,10 @@ class PagesLoader extends Wire {
|
||||
$pageArray = $rows['pageArray'];
|
||||
$pageArray->setTrackChanges(false);
|
||||
$paginationTotal = $pageArray->getTotal();
|
||||
|
||||
/** @var array $joinResults PageFinder sets which fields supported autojoin true|false */
|
||||
$joinResults = $pageArray->data('joinFields');
|
||||
|
||||
unset($rows['pageArray']);
|
||||
|
||||
foreach($rows as $row) {
|
||||
@@ -667,6 +671,7 @@ class PagesLoader extends Wire {
|
||||
// set blank values where joinField didn't appear on page row
|
||||
foreach($joinFields as $joinField) {
|
||||
if(isset($row["{$joinField}__data"])) continue;
|
||||
if(empty($joinResults[$joinField])) continue; // field did not support autojoin
|
||||
if(!$template->fieldgroup->hasField($joinField)) continue;
|
||||
$field = $page->getField($joinField);
|
||||
if(!$field || !$field->type) continue;
|
||||
|
Reference in New Issue
Block a user