mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 16:54:44 +02:00
Fix processwire/processwire-issues#49 where locked InputfieldPage still loaded all selectable pages when not necessary to do so
This commit is contained in:
@@ -399,15 +399,16 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
*
|
||||
* #pw-group-retrieval
|
||||
*
|
||||
* @param WireArray|WireData|string $items May be any of the following:
|
||||
* @param WireArray|WireData|string|null $items May be any of the following:
|
||||
* - `WireData` object (or derivative)
|
||||
* - `WireArray` object (or derivative)
|
||||
* - Name of any property from this object that returns one of the above.
|
||||
* - Omit argument to simply return this object in a WireArray
|
||||
* @return WireArray Returns a WireArray of this object *and* the one(s) given.
|
||||
* @throws WireException If invalid argument supplied.
|
||||
*
|
||||
*/
|
||||
public function ___and($items) {
|
||||
public function ___and($items = null) {
|
||||
|
||||
if(is_string($items)) $items = $this->get($items);
|
||||
|
||||
@@ -415,13 +416,13 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
|
||||
// great, that's what we want
|
||||
$a = clone $items;
|
||||
$a->prepend($this);
|
||||
} else if($items instanceof WireData) {
|
||||
} else if($items instanceof WireData || is_null($items)) {
|
||||
// single item
|
||||
$className = $this->className(true) . 'Array';
|
||||
if(!class_exists($className)) $className = wireClassName('WireArray', true);
|
||||
$a = $this->wire(new $className());
|
||||
if(!class_exists($className)) $className = wireClassName('WireArray', true);
|
||||
$a = $this->wire(new $className());
|
||||
$a->add($this);
|
||||
$a->add($items);
|
||||
if($items) $a->add($items);
|
||||
} else {
|
||||
// unknown
|
||||
throw new WireException('Invalid argument provided to WireData::and(...)');
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* Delegates the actual input control to a user-defined Inputfield derived from InputfieldSelect
|
||||
*
|
||||
* @method PageArray getSelectablePages(Page $page)
|
||||
* @method PageArray|null getSelectablePages(Page $page)
|
||||
* @method PageArray findPagesCode(Page $page)
|
||||
*
|
||||
* Can be accessed from $this or from $field:
|
||||
@@ -92,6 +92,14 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
||||
*/
|
||||
protected $processInputMode = false;
|
||||
|
||||
/**
|
||||
* True when in renderValue mode
|
||||
*
|
||||
* @var bool
|
||||
*
|
||||
*/
|
||||
protected $renderValueMode = false;
|
||||
|
||||
/**
|
||||
* PageArray of pages that were added in the request
|
||||
*
|
||||
@@ -292,17 +300,27 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
||||
* Return PageArray of selectable pages for this input
|
||||
*
|
||||
* @param Page $page The Page being edited
|
||||
* @return PageArray
|
||||
* @return PageArray|null
|
||||
*
|
||||
*/
|
||||
public function ___getSelectablePages(Page $page) {
|
||||
|
||||
|
||||
$lockedModes = array(Inputfield::collapsedNoLocked, Inputfield::collapsedYesLocked);
|
||||
$statusUnder = $this->allowUnpub ? Page::statusTrash : Page::statusUnpublished;
|
||||
$children = null;
|
||||
|
||||
if($this->configMode) {
|
||||
$children = $this->wire('pages')->newPageArray();
|
||||
|
||||
} else if($this->renderValueMode || in_array($this->getSetting('collapsed'), $lockedModes)) {
|
||||
$children = $this->attr('value');
|
||||
// convert to PageArray if not already
|
||||
if($children instanceof Page) {
|
||||
$children = $children->and();
|
||||
} else if(!$children instanceof PageArray) {
|
||||
$children = $this->wire('pages')->newPageArray();
|
||||
}
|
||||
|
||||
} else if($this->findPagesSelector) {
|
||||
// a find() selector
|
||||
$instance = $this->processInputMode ? $this : null;
|
||||
@@ -316,7 +334,13 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
||||
|
||||
} else if($this->parent_id) {
|
||||
$parent = $this->wire('pages')->get($this->parent_id);
|
||||
if($parent) $children = $this->template_id ? $parent->children("templates_id={$this->template_id}, check_access=0, status<$statusUnder") : $parent->children("check_access=0, status<$statusUnder");
|
||||
if($parent) {
|
||||
if($this->template_id) {
|
||||
$children = $parent->children("templates_id={$this->template_id}, check_access=0, status<$statusUnder");
|
||||
} else {
|
||||
$children = $parent->children("check_access=0, status<$statusUnder");
|
||||
}
|
||||
}
|
||||
|
||||
} else if($this->template_id) {
|
||||
$children = $this->pages->find("templates_id={$this->template_id}, check_access=0, status<$statusUnder");
|
||||
@@ -515,11 +539,10 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
|
||||
public function renderReady(Inputfield $parent = null, $renderValueMode = false) {
|
||||
|
||||
|
||||
$this->renderValueMode = $renderValueMode;
|
||||
parent::renderReady($parent, $renderValueMode);
|
||||
|
||||
$inputfield = $this->getInputfield();
|
||||
|
||||
if(!$inputfield) {
|
||||
@@ -660,7 +683,7 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
||||
$value = $this->attr('value');
|
||||
|
||||
if(is_array($value) || $value instanceof PageArray) {
|
||||
$out = '<ul class="PageArray">';
|
||||
$out = '<ul class="PageArray pw-bullets">';
|
||||
foreach($value as $p) {
|
||||
$of = $p->of();
|
||||
$p->of(true);
|
||||
|
Reference in New Issue
Block a user