mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 00:06:55 +02:00
Fix issue processwire/processwire-issues#2 to support better handling of unpublished pages in certain Page input types when unpublished pages are not allowed in the field.
This commit is contained in:
@@ -489,6 +489,8 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
$inputfield->set($key, $value);
|
$inputfield->set($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$inputfield->set('allowUnpub', $this->getSetting('allowUnpub'));
|
||||||
|
|
||||||
$this->inputfieldWidget = $inputfield;
|
$this->inputfieldWidget = $inputfield;
|
||||||
|
|
||||||
return $inputfield;
|
return $inputfield;
|
||||||
@@ -692,7 +694,15 @@ class InputfieldPage extends Inputfield implements ConfigurableModule {
|
|||||||
if($id > 0) {
|
if($id > 0) {
|
||||||
// existing page
|
// existing page
|
||||||
$page = $this->wire('pages')->get($id);
|
$page = $this->wire('pages')->get($id);
|
||||||
if($page->hasStatus(Page::statusUnpublished) && !$this->getSetting('allowUnpub')) continue; // disallow unpublished
|
if($page->hasStatus(Page::statusUnpublished) && !$this->getSetting('allowUnpub')) {
|
||||||
|
// disallow unpublished
|
||||||
|
$warning = sprintf($this->_('Unpublished page %1$s is not allowed in field "%2$s"'), $page->path, $this->label);
|
||||||
|
if($this->wire('user')->isSuperuser()) {
|
||||||
|
$warning .= ' ' . sprintf($this->_('To allow unpublished pages, edit the "%s" field and see the setting on the "Advanced" tab.'), $this->name);
|
||||||
|
}
|
||||||
|
$this->warning($warning);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// placeholder for new page, to be sorted later
|
// placeholder for new page, to be sorted later
|
||||||
$page = $this->wire('pages')->newNullPage();
|
$page = $this->wire('pages')->newNullPage();
|
||||||
|
@@ -22,6 +22,9 @@
|
|||||||
* @property bool $useAndWords When true, each word will be isolated to a separate searchFields=searchValue, which enables it to duplicate ~= operator behavior while using a %= operator (default=false).
|
* @property bool $useAndWords When true, each word will be isolated to a separate searchFields=searchValue, which enables it to duplicate ~= operator behavior while using a %= operator (default=false).
|
||||||
* @property int $lang_id Force use of this language for results
|
* @property int $lang_id Force use of this language for results
|
||||||
*
|
*
|
||||||
|
* @method string renderList()
|
||||||
|
* @method string renderListItem($label, $value, $class = '')
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class InputfieldPageAutocomplete extends Inputfield implements InputfieldHasArrayValue {
|
class InputfieldPageAutocomplete extends Inputfield implements InputfieldHasArrayValue {
|
||||||
|
|
||||||
@@ -29,7 +32,7 @@ class InputfieldPageAutocomplete extends Inputfield implements InputfieldHasArra
|
|||||||
return array(
|
return array(
|
||||||
'title' => __('Page Auto Complete', __FILE__), // Module Title
|
'title' => __('Page Auto Complete', __FILE__), // Module Title
|
||||||
'summary' => __('Multiple Page selection using auto completion and sorting capability. Intended for use as an input field for Page reference fields.', __FILE__), // Module Summary
|
'summary' => __('Multiple Page selection using auto completion and sorting capability. Intended for use as an input field for Page reference fields.', __FILE__), // Module Summary
|
||||||
'version' => 111,
|
'version' => 112,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,11 +86,19 @@ class InputfieldPageAutocomplete extends Inputfield implements InputfieldHasArra
|
|||||||
|
|
||||||
// Force Language when applicable
|
// Force Language when applicable
|
||||||
$this->set('lang_id', 0);
|
$this->set('lang_id', 0);
|
||||||
|
|
||||||
|
// Whether to allow unpublished pages (null=not set, 0|false=no, 1|true=yes)
|
||||||
|
$this->set('allowUnpub', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a selected list item
|
* Render a selected list item
|
||||||
*
|
*
|
||||||
|
* @param string $label
|
||||||
|
* @param string $value
|
||||||
|
* @param string $class
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
protected function ___renderListItem($label, $value, $class = '') {
|
protected function ___renderListItem($label, $value, $class = '') {
|
||||||
if($class) $class = " $class";
|
if($class) $class = " $class";
|
||||||
@@ -106,6 +117,8 @@ class InputfieldPageAutocomplete extends Inputfield implements InputfieldHasArra
|
|||||||
/**
|
/**
|
||||||
* Render the selected items list
|
* Render the selected items list
|
||||||
*
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
protected function ___renderList() {
|
protected function ___renderList() {
|
||||||
|
|
||||||
@@ -229,6 +242,9 @@ _OUT;
|
|||||||
/**
|
/**
|
||||||
* Convert the CSV string provided in the $input to an array of ints needed for this fieldtype
|
* Convert the CSV string provided in the $input to an array of ints needed for this fieldtype
|
||||||
*
|
*
|
||||||
|
* @param WireInputData $input
|
||||||
|
* @return $this
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function ___processInput(WireInputData $input) {
|
public function ___processInput(WireInputData $input) {
|
||||||
|
|
||||||
@@ -279,6 +295,11 @@ _OUT;
|
|||||||
$selector .= ",lang_id=" . (int) $this->lang_id;
|
$selector .= ",lang_id=" . (int) $this->lang_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$allowUnpub = $this->getSetting('allowUnpub');
|
||||||
|
if(!is_null($allowUnpub) && !$allowUnpub) {
|
||||||
|
$selector .= ",status<" . Page::statusUnpublished;
|
||||||
|
}
|
||||||
|
|
||||||
// allow for full site matches
|
// allow for full site matches
|
||||||
if(!strlen($selector)) $selector = "id>0";
|
if(!strlen($selector)) $selector = "id>0";
|
||||||
|
|
||||||
@@ -341,6 +362,7 @@ _OUT;
|
|||||||
$fieldset->collapsed = Inputfield::collapsedYes;
|
$fieldset->collapsed = Inputfield::collapsedYes;
|
||||||
|
|
||||||
$recommended = $this->_('Recommended');
|
$recommended = $this->_('Recommended');
|
||||||
|
/** @var InputfieldRadios $field */
|
||||||
$field = $this->modules->get('InputfieldRadios');
|
$field = $this->modules->get('InputfieldRadios');
|
||||||
$field->setAttribute('name', 'operator');
|
$field->setAttribute('name', 'operator');
|
||||||
$field->label = $this->_('Autocomplete search operator');
|
$field->label = $this->_('Autocomplete search operator');
|
||||||
@@ -357,6 +379,7 @@ _OUT;
|
|||||||
$field->collapsed = Inputfield::collapsedNo;
|
$field->collapsed = Inputfield::collapsedNo;
|
||||||
$fieldset->add($field);
|
$fieldset->add($field);
|
||||||
|
|
||||||
|
/** @var InputfieldText $field */
|
||||||
$field = $this->modules->get('InputfieldText');
|
$field = $this->modules->get('InputfieldText');
|
||||||
$field->attr('name', 'searchFields');
|
$field->attr('name', 'searchFields');
|
||||||
$field->label = $this->_('Fields to query for autocomplete');
|
$field->label = $this->_('Fields to query for autocomplete');
|
||||||
|
Reference in New Issue
Block a user