mirror of
https://github.com/processwire/processwire.git
synced 2025-08-16 11:44:42 +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,14 +104,25 @@ class FieldtypeSelector extends Fieldtype {
|
||||
|
||||
public function ___getConfigInputfields(Field $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->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->notes = $this->_('Example: template=product');
|
||||
$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;
|
||||
}
|
||||
|
@@ -740,7 +740,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
||||
protected function renderTestSelector($selector) {
|
||||
try {
|
||||
$selector = $this->sanitizeSelectorString($selector);
|
||||
$cnt = $this->wire('pages')->count($selector, array('allowCustom' => true));
|
||||
$cnt = $this->wire()->pages->count($selector, array('allowCustom' => true));
|
||||
$out = '';
|
||||
// take into account a limit=n
|
||||
if(strpos($selector, 'limit=') !== false && preg_match('/\blimit=(\d+)/', $selector, $matches)) {
|
||||
@@ -755,12 +755,22 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
||||
$bookmark = array(
|
||||
'defaultSelector' => $selector,
|
||||
'initSelector' => $this->initValue,
|
||||
);
|
||||
);
|
||||
$previewColumns = $this->sessionGet('previewColumns');
|
||||
if($previewColumns && is_string($previewColumns)) $previewColumns = explode(',', $previewColumns);
|
||||
if(is_array($previewColumns) && count($previewColumns)) $bookmark['columns'] = $previewColumns;
|
||||
$this->wire('modules')->includeModule('ProcessPageLister');
|
||||
$id = ((int) $this->wire('input')->get('id')) . '_' . $this->attr('name');
|
||||
if($previewColumns && is_string($previewColumns)) {
|
||||
$previewColumns = explode(',', str_replace(' ', ',', $previewColumns));
|
||||
}
|
||||
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);
|
||||
if($url) {
|
||||
$title = $this->_('Pages that match your selector');
|
||||
|
Reference in New Issue
Block a user