mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 12:10:45 +02:00
Add @adrianbj PR #214 which adds a configurable columns option for Selector fields.
Co-authored-by: adrianbj <adrian@visualscience.ca>
This commit is contained in:
@@ -104,8 +104,10 @@ class FieldtypeSelector extends Fieldtype {
|
|||||||
|
|
||||||
public function ___getConfigInputfields(Field $field) {
|
public function ___getConfigInputfields(Field $field) {
|
||||||
$inputfields = parent::___getConfigInputfields($field);
|
$inputfields = parent::___getConfigInputfields($field);
|
||||||
|
$modules = $this->wire()->modules;
|
||||||
|
|
||||||
$f = $this->wire('modules')->get('InputfieldText');
|
/** @var InputfieldText $f */
|
||||||
|
$f = $modules->get('InputfieldText');
|
||||||
$f->attr('name', 'initValue');
|
$f->attr('name', 'initValue');
|
||||||
$f->label = $this->_('Initial Selector Value');
|
$f->label = $this->_('Initial Selector Value');
|
||||||
$f->description = $this->_('Enter an initial selector string that will be used as the enforced starting point for any selectors generated from this field. Any pages matching the user selector will be bound within the selector you enter here.');
|
$f->description = $this->_('Enter an initial selector string that will be used as the enforced starting point for any selectors generated from this field. Any pages matching the user selector will be bound within the selector you enter here.');
|
||||||
@@ -113,6 +115,15 @@ class FieldtypeSelector extends Fieldtype {
|
|||||||
$f->attr('value', $field->get('initValue') ? $field->get('initValue') : '');
|
$f->attr('value', $field->get('initValue') ? $field->get('initValue') : '');
|
||||||
$inputfields->add($f);
|
$inputfields->add($f);
|
||||||
|
|
||||||
|
/** @var InputfieldText $f */
|
||||||
|
$f = $modules->get('InputfieldText');
|
||||||
|
$f->attr('name', 'previewColumns');
|
||||||
|
$f->label = $this->_('Preview Columns');
|
||||||
|
$f->description = $this->_('Enter a CSV string of columns/field names to show in previews generated from this field.');
|
||||||
|
$f->notes = $this->_('Example: name, template, parent, id');
|
||||||
|
$f->attr('value', $field->get('previewColumns') ? $field->get('previewColumns') : '');
|
||||||
|
$inputfields->add($f);
|
||||||
|
|
||||||
return $inputfields;
|
return $inputfields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -740,7 +740,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
protected function renderTestSelector($selector) {
|
protected function renderTestSelector($selector) {
|
||||||
try {
|
try {
|
||||||
$selector = $this->sanitizeSelectorString($selector);
|
$selector = $this->sanitizeSelectorString($selector);
|
||||||
$cnt = $this->wire('pages')->count($selector, array('allowCustom' => true));
|
$cnt = $this->wire()->pages->count($selector, array('allowCustom' => true));
|
||||||
$out = '';
|
$out = '';
|
||||||
// take into account a limit=n
|
// take into account a limit=n
|
||||||
if(strpos($selector, 'limit=') !== false && preg_match('/\blimit=(\d+)/', $selector, $matches)) {
|
if(strpos($selector, 'limit=') !== false && preg_match('/\blimit=(\d+)/', $selector, $matches)) {
|
||||||
@@ -757,10 +757,20 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
'initSelector' => $this->initValue,
|
'initSelector' => $this->initValue,
|
||||||
);
|
);
|
||||||
$previewColumns = $this->sessionGet('previewColumns');
|
$previewColumns = $this->sessionGet('previewColumns');
|
||||||
if($previewColumns && is_string($previewColumns)) $previewColumns = explode(',', $previewColumns);
|
if($previewColumns && is_string($previewColumns)) {
|
||||||
if(is_array($previewColumns) && count($previewColumns)) $bookmark['columns'] = $previewColumns;
|
$previewColumns = explode(',', str_replace(' ', ',', $previewColumns));
|
||||||
$this->wire('modules')->includeModule('ProcessPageLister');
|
}
|
||||||
$id = ((int) $this->wire('input')->get('id')) . '_' . $this->attr('name');
|
if(is_array($previewColumns) && count($previewColumns)) {
|
||||||
|
$a = array();
|
||||||
|
$sanitizer = $this->wire()->sanitizer;
|
||||||
|
foreach($previewColumns as $key => $col) {
|
||||||
|
$col = empty($col) ? '' : $sanitizer->name($col);
|
||||||
|
if(strlen("$col")) $a[] = $col;
|
||||||
|
}
|
||||||
|
if(count($a)) $bookmark['columns'] = $a;
|
||||||
|
}
|
||||||
|
$this->wire()->modules->includeModule('ProcessPageLister');
|
||||||
|
$id = ((int) $this->wire()->input->get('id')) . '_' . $this->attr('name');
|
||||||
$url = ProcessPageLister::addSessionBookmark($id, $bookmark);
|
$url = ProcessPageLister::addSessionBookmark($id, $bookmark);
|
||||||
if($url) {
|
if($url) {
|
||||||
$title = $this->_('Pages that match your selector');
|
$title = $this->_('Pages that match your selector');
|
||||||
|
Reference in New Issue
Block a user