__('Page List Select Multiple', __FILE__), // Module Title 'summary' => __('Selection of multiple pages from a ProcessWire page tree list', __FILE__), // Module Summary 'version' => 101, 'permanent' => true, ); } public function init() { parent::init(); $this->fuel('modules')->get('ProcessPageList'); // prerequisite modules $this->set('parent_id', 0); $this->set('labelFieldName', 'title'); $this->set('startLabel', $this->_('Add')); $this->set('cancelLabel', $this->_('Cancel')); $this->set('selectLabel', $this->_('Select')); $this->set('unselectLabel', $this->_('Unselect')); $this->set('moreLabel', $this->_('More')); } protected function renderListItem($label, $value, $class = '') { if($class) $class = " $class"; $out = "\n
  • " . "" . "$value" . "$label " . "remove" . "
  • "; return $out; } public function ___render() { if(!strlen($this->parent_id)) { return "

    " . $this->_('Unable to render this field due to missing parent page in field settings.') . '

    '; } $out = "\n
      " . $this->renderListItem("Label", "1", "itemTemplate"); foreach($this->value as $page_id) { $page = $this->pages->get((int) $page_id); if(!$page || !$page->id) continue; $out .= $this->renderListItem($page->get("$this->labelFieldName|name"), $page->id); } $out .= "\n
    "; $attrs = $this->getAttributes(); unset($attrs['value']); $value = implode(',', $this->value); $attrStr = $this->getAttributesString($attrs) . " value='$value'"; $out .= "\n"; $out .= "\n"; return $out; } /** * Convert the CSV string provide in the $input to an array of ints needed for this fieldtype * */ public function ___processInput(WireInputData $input) { parent::___processInput($input); $value = $this->attr('value'); if(is_array($value)) $value = reset($value); $value = trim($value); if(strpos($value, ",") !== false) $value = explode(",", $value); else if($value) $value = array($value); else $value = array(); foreach($value as $k => $v) { $value[$k] = (int) $v; } $this->attr('value', $value); return $this; } }