public function addSelect($label, $url, $name, $options, $selected_option = false, $attributes = array()) { $widget = new SelectWidget($label, $url, $name); $widget->layout = false; foreach ($options as $value => $option_label) { $widget->addElement(new SelectElement($value, $option_label, $value === $selected_option)); } $widget->attributes = array_merge($widget->attributes, $attributes); $content = $widget->render(); $this->addElement(new WidgetElement($content)); }
/** * Populates and renders the widget according to the previously made * settings. */ public function render($variables = array()) { $current_id = Request::get($this->template_variables['name']); if (!$current_id && !$this->include_all) { $current_id = Semester::findCurrent()->id; } if ($this->include_all) { $element = new SelectElement(0, _('Alle Semester'), !$current_id); $this->addElement($element); } $semesters = array_reverse(Semester::getAll()); foreach ($semesters as $semester) { $element = new SelectElement($semester->id, $semester->name, $current_id && $semester->id == $current_id); $this->addElement($element); } return parent::render($variables); }