diff --git a/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelect.module b/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelect.module index 4882afde..594ab7a4 100644 --- a/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelect.module +++ b/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelect.module @@ -1,8 +1,13 @@ __('Selection of a single page from a ProcessWire page tree list', __FILE__), // Module Summary 'version' => 101, 'permanent' => true, - ); + ); } public function init() { @@ -35,23 +42,15 @@ class InputfieldPageListSelect extends Inputfield implements InputfieldPageListS $this->set('showPath', false); parent::init(); } - + public function renderReady(Inputfield $parent = null, $renderValueMode = false) { - static $process = null; - if(is_null($process)) { - /** @var ProcessPageList $process */ - $process = $this->wire('modules')->get('ProcessPageList'); // prerequisite module - $process->setPageLabelField($this->attr('name'), $this->labelFieldName); - $process->renderReady(); - } + $this->pageListReady($this->attr('name'), $this->labelFieldName); return parent::renderReady($parent, $renderValueMode); } - + public function ___render() { - if(!strlen($this->parent_id)) { - return "
" . $this->_('Unable to render this field due to missing parent page in field settings.') . "
"; - } + if(!strlen("$this->parent_id")) return $this->renderParentError(); $this->addClass('InputfieldPageListSelectData'); $attrs = $this->getAttributes(); @@ -69,7 +68,11 @@ class InputfieldPageListSelect extends Inputfield implements InputfieldPageListS return $out; } - + + public function ___renderValue() { + return $this->renderMarkupValue($this->val()); + } + public function ___processInput(WireInputData $input) { parent::___processInput($input); $this->value = (int) $this->value; diff --git a/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectCommon.php b/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectCommon.php new file mode 100644 index 00000000..51a748ad --- /dev/null +++ b/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectCommon.php @@ -0,0 +1,84 @@ +pageList) return; + $this->pageList = $this->wire()->modules->get('ProcessPageList'); // prerequisite module + $this->pageList->setPageLabelField($name, $labelFieldName); + $this->pageList->renderReady(); + } + + /** + * Render markup value for PageListSelect/PageListSelectMultiple + * + * @param int|int[] $value + * @return string + * + */ + public function renderMarkupValue($value) { + if(empty($value)) return ''; + $pages = $this->wire()->pages; + if(is_array($value)) { + $labels = array(); + foreach($value as $id) { + $page = $pages->get((int) "$id"); + $labels[] = $this->getPageLabel($page); + } + return '$label
"; + } + } + + /** + * Get label to represent given $page + * + * @param Page $page + * @return string + * + */ + public function getPageLabel(Page $page) { + if(!$page->id) return ''; + if(!$page->viewable(false)) { + $label = sprintf($this->_('Page %d not viewable'), $page->id); + } else if($this->hasInputfield instanceof InputfieldPage) { + $label = $this->hasInputfield->getPageLabel($page); + } else { + $label = $page->getUnformatted('title|name'); + } + return $this->wire()->sanitizer->entities($label); + } + + /** + * @return string + * + */ + public function renderParentError() { + return + "" . + $this->_('Unable to render this field due to missing parent page in field settings.') . + "
"; + } +} diff --git a/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectMultiple.module b/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectMultiple.module index 6dfd51cd..a986cb7b 100644 --- a/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectMultiple.module +++ b/wire/modules/Inputfield/InputfieldPageListSelect/InputfieldPageListSelectMultiple.module @@ -1,17 +1,20 @@ __('Page List Select Multiple', __FILE__), // Module Title @@ -38,47 +43,53 @@ class InputfieldPageListSelectMultiple extends Inputfield $this->set('parent_id', 0); $this->set('labelFieldName', 'title'); $this->set('startLabel', $this->_('Add')); - $this->set('cancelLabel', $this->_('Cancel')); + $this->set('cancelLabel', $this->_('Close')); $this->set('selectLabel', $this->_('Select')); + $this->set('selectedLabel', $this->_('Selected')); $this->set('unselectLabel', $this->_('Unselect')); $this->set('moreLabel', $this->_('More')); $this->set('removeLabel', $this->_('Remove')); } + /** + * @param string $label Entity encoded label text + * @param int $value + * @param string $class + * @return string + * @throws WireException + * + */ protected function renderListItem($label, $value, $class = '') { if($class) $class = " $class"; + $sanitizer = $this->wire()->sanitizer; + $sortIcon = wireIconMarkup('arrows itemSort'); + $trashIcon = wireIconMarkup('trash'); + $trashLabel = $sanitizer->entities1($this->removeLabel); $out = "" . $this->_('Unable to render this field due to missing parent page in field settings.') . '
'; - } + if(!strlen("$this->parent_id")) return $this->renderParentError(); $out = "$out
"; + } + } else { + bd($this->options); } return $out; diff --git a/wire/modules/Inputfield/InputfieldText/InputfieldText.module b/wire/modules/Inputfield/InputfieldText/InputfieldText.module index eb9ed048..a3837299 100644 --- a/wire/modules/Inputfield/InputfieldText/InputfieldText.module +++ b/wire/modules/Inputfield/InputfieldText/InputfieldText.module @@ -126,6 +126,12 @@ class InputfieldText extends Inputfield { return $out; } + public function ___renderValue() { + $value = (string) $this->val(); + if(!strlen($value)) return ''; + return '' . $this->wire()->sanitizer->entities($value) . '
'; + } + /** * Get all attributes in an associative array *