mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 00:06:55 +02:00
Update FieldtypePage.getMatchQuery to inherit "include=" and "check_access=0" settings from PageFinder that called upon it. Update PageFinder to support this kind of communication with Fieldtypes.
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
* @method void getQueryJoinPath(DatabaseQuerySelect $query, $selector)
|
||||
* @method bool|Field getQueryUnknownField($fieldName, array $data);
|
||||
*
|
||||
* @property string $includeMode
|
||||
* @property bool $checkAccess
|
||||
*
|
||||
*/
|
||||
|
||||
class PageFinder extends Wire {
|
||||
@@ -393,6 +396,12 @@ class PageFinder extends Wire {
|
||||
// protected $extraJoins = array();
|
||||
// protected $nativeWheres = array(); // where statements for native fields, to be reused in subselects where appropriate.
|
||||
|
||||
public function __get($key) {
|
||||
if($key === 'includeMode') return $this->includeMode;
|
||||
if($key === 'checkAccess') return $this->checkAccess;
|
||||
return parent::__get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize new find operation and prepare options
|
||||
*
|
||||
@@ -1687,6 +1696,7 @@ class PageFinder extends Wire {
|
||||
$q->set('selector', $selector); // original selector if required by the fieldtype
|
||||
$q->set('selectors', $selectors); // original selectors (all) if required by the fieldtype
|
||||
$q->set('parentQuery', $query);
|
||||
$q->set('pageFinder', $this);
|
||||
$q->bindOption('global', true); // ensures bound value key are globally unique
|
||||
$q->bindOption('prefix', 'pf'); // pf=PageFinder
|
||||
|
||||
@@ -3469,6 +3479,7 @@ class PageFinder extends Wire {
|
||||
* @property Selector $selector Original Selector object
|
||||
* @property Selectors $selectors Original Selectors object
|
||||
* @property DatabaseQuerySelect $parentQuery Parent database query
|
||||
* @property PageFinder $pageFinder PageFinder instance that initiated the query
|
||||
*/
|
||||
abstract class PageFinderDatabaseQuerySelect extends DatabaseQuerySelect { }
|
||||
|
||||
|
@@ -1092,7 +1092,7 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
*
|
||||
* Note: $field->findPagesCode is not implemented and thus not supported here.
|
||||
*
|
||||
* @param DatabaseQuerySelect $query
|
||||
* @param DatabaseQuerySelect|PageFinderDatabaseQuerySelect $query
|
||||
* @param string $table
|
||||
* @param string $subfield
|
||||
* @param string $operator
|
||||
@@ -1103,18 +1103,35 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
*/
|
||||
protected function getMatchQueryCustom($query, $table, $subfield, $operator, $value) {
|
||||
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$field = $query->field;
|
||||
$group = $query->group;
|
||||
$table = $database->escapeTable($table);
|
||||
$selector = 'include=hidden, '; // @todo should $selector include check_access=0 or even include=all?
|
||||
$pageFinder = $this->wire(new PageFinder());
|
||||
$pageFinderOptions = array('getTotal' => false);
|
||||
$value = $this->wire('sanitizer')->selectorValue($value);
|
||||
$value = $this->wire()->sanitizer->selectorValue($value);
|
||||
$findPagesSelector = $field->get('findPagesSelector');
|
||||
if(empty($findPagesSelector)) $findPagesSelector = $field->get('findPagesSelect');
|
||||
$parent_id = $field->get('parent_id');
|
||||
$template_ids = self::getTemplateIDs($field, true);
|
||||
$selector = '';
|
||||
|
||||
if($query->pageFinder) {
|
||||
$pf = $query->pageFinder;
|
||||
$pfo = $pf->getOptions();
|
||||
if(empty($pfo['findAll']) === true) {
|
||||
$selector = "include=all, $selector";
|
||||
} else if($pf->includeMode) {
|
||||
$selector = "include=$pf->includeMode, $selector";
|
||||
} else {
|
||||
$selector = "include=hidden, $selector";
|
||||
}
|
||||
if($pf->checkAccess === false) {
|
||||
$selector = "check_access=0, $selector";
|
||||
}
|
||||
} else {
|
||||
$selector = "include=hidden, $selector";
|
||||
}
|
||||
|
||||
if(in_array($subfield, $this->nativeNames)) {
|
||||
// fine then, we can handle that here when needed (like !=)
|
||||
@@ -1125,8 +1142,10 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
|
||||
}
|
||||
|
||||
if($findPagesSelector) {
|
||||
// remove the existing include=hidden, only if selector specifies a different include=something
|
||||
if(strpos($findPagesSelector, 'include=') !== false) $selector = '';
|
||||
// remove the existing include=hidden|all|unpublished, only if selector specifies a different include=something
|
||||
if(strpos($findPagesSelector, 'include=') !== false) {
|
||||
$selector = preg_replace('/include=[a-z]+,/', '', $selector);
|
||||
}
|
||||
$selector .= $findPagesSelector . ", ";
|
||||
if(strpos($selector, 'page.') !== false) {
|
||||
// remove any page.property from selector as it won't be applicable during a getMatchQuery
|
||||
|
Reference in New Issue
Block a user