SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/RefineWidgetSelect.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. /**
  17. * A textbox widget
  18. **/
  19. class RefineWidgetSelect extends RefineWidget
  20. {
  21. private $items;
  22.  
  23. public function __construct($name, $label, $items)
  24. {
  25. parent::__construct($name, $label);
  26. $this->items = $items;
  27. }
  28.  
  29. /**
  30.   * Draws the widget.
  31.   * @return string The HTML for the widget.
  32.   **/
  33. public function render()
  34. {
  35. $name = Enc::html($this->name);
  36. $label = Enc::html($this->label);
  37.  
  38. $out = "<div class=\"field-element field-element--white field-element--small field-element--select refine-bar-{$name}\">";
  39. $out .= "<div class=\"field-label\">";
  40. $out .= "<label for=\"field1\">{$label}</label>";
  41. $out .= "</div>";
  42. $out .= "<div class=\"field-input\">";
  43. $out .= "<select name=\"{$name}\">";
  44. $out .= "<option value=\"\">- Select -</option>";
  45.  
  46. $selected_key = Enc::html($this->getValue());
  47. foreach ($this->items as $key => $val) {
  48. $key = Enc::html($key);
  49. $val = Enc::html($val);
  50.  
  51. if ($key == $selected_key) {
  52. $out .= "<option value=\"{$key}\" selected>{$val}</option>";
  53. } else {
  54. $out .= "<option value=\"{$key}\">{$val}</option>";
  55. }
  56. }
  57.  
  58. $out .= "</select>";
  59. $out .= "</div>";
  60. $out .= "</div>";
  61.  
  62.  
  63.  
  64. return $out;
  65. }
  66.  
  67. }
  68.  
  69.  
  70.