1<?php 2 3class ohrmWidgetButton extends sfWidget { 4 5 protected $name; 6 protected $label; 7 protected $attributes; 8 9 public function __construct($name, $label, $attributes = null) { 10 if (empty($attributes)) { 11 $attributes = array(); 12 } 13 14 $this->name = $name; 15 $this->label = $label; 16 $this->attributes = empty($attributes) ? array() : $attributes; 17 } 18 19 /** 20 * @return string An HTML tag string 21 */ 22 public function render($name, $value = null, $attributes = array(), $errors = array()) { 23 if (empty($name)) { 24 $name = $this->name; 25 } 26 27 if (empty($value)) { 28 $value = $this->label; 29 } 30 31 if (empty($attributes)) { 32 $attributes = $this->attributes; 33 } 34 35 if (is_array($attributes)) { 36 if (!array_key_exists('id', $attributes)) { 37 $attributes['id'] = $name; 38 } 39 if (!array_key_exists('class', $attributes)) { 40 $attributes['class'] = 'plainbtn'; 41 } 42 } else { 43 $attributes['id'] = $name; 44 $attributes['class'] = 'plainbtn'; 45 } 46 47 return $this->renderTag('input', array_merge(array('type' => 'button', 'name' => $name, 'value' => __($value)), $attributes)); 48 } 49 50 public function getDefault() { 51 if (!array_key_exists('value', $this->attributes)) { 52 $this->attributes['value'] = $this->label; 53 } 54 55 return $this->attributes; 56 } 57 58 public function getName() { 59 return $this->name; 60 } 61 62} 63