config->prompt)) $this->placeholder = trans($this->config->prompt); if (isset($this->config->partial)) $this->customPartial = $this->config->partial; if (isset($this->config->growable)) $this->growable = $this->config->growable; /* * Add CSS class styles */ $this->cssClasses[] = 'icon search'; if ($this->growable) $this->cssClasses[] = 'growable'; } /** * Renders the widget. */ public function render() { $this->prepareVars(); if ($this->customPartial) return $this->controller->makePartial($this->customPartial); else return $this->makePartial('search'); } /** * Prepares the view data */ public function prepareVars() { $this->vars['cssClasses'] = implode(' ', $this->cssClasses); $this->vars['placeholder'] = $this->placeholder; $this->vars['value'] = $this->getActiveTerm(); } /** * Search field has been submitted. */ public function onSubmit() { /* * Save or reset search term in session */ $this->setActiveTerm(post($this->getName())); /* * Trigger class event, merge results as viewable array */ $params = func_get_args(); $result = $this->fireEvent('search.submit', [$params]); if ($result && is_array($result)) return Util::arrayMerge($result); } /** * Returns an active search term for this widget instance. */ public function getActiveTerm() { return $this->activeTerm = $this->getSession('term', ''); } /** * Sets an active search term for this widget instance. */ public function setActiveTerm($term) { if (strlen($term)) $this->putSession('term', $term); else $this->resetSession(); $this->activeTerm = $term; } /** * Returns a value suitable for the field name property. * @return string */ public function getName() { return $this->alias . '[term]'; } }