PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Nette/Forms/Controls/ImageButton.php

https://github.com/DocX/nette
PHP | 75 lines | 23 code | 16 blank | 36 comment | 0 complexity | 71095123b5d3722f817a6b5d8777b501 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt.
  9. *
  10. * For more information please see http://nettephp.com
  11. *
  12. * @copyright Copyright (c) 2004, 2009 David Grudl
  13. * @license http://nettephp.com/license Nette license
  14. * @link http://nettephp.com
  15. * @category Nette
  16. * @package Nette\Forms
  17. */
  18. /*namespace Nette\Forms;*/
  19. require_once dirname(__FILE__) . '/../../Forms/Controls/SubmitButton.php';
  20. /**
  21. * Submittable image button form control.
  22. *
  23. * @author David Grudl
  24. * @copyright Copyright (c) 2004, 2009 David Grudl
  25. * @package Nette\Forms
  26. */
  27. class ImageButton extends SubmitButton
  28. {
  29. /**
  30. * @param string URI of the image
  31. * @param string alternate text for the image
  32. */
  33. public function __construct($src = NULL, $alt = NULL)
  34. {
  35. parent::__construct();
  36. $this->control->type = 'image';
  37. $this->control->src = $src;
  38. $this->control->alt = $alt;
  39. }
  40. /**
  41. * Returns name of control within a Form & INamingContainer scope.
  42. * @return string
  43. */
  44. public function getHtmlName()
  45. {
  46. $name = parent::getHtmlName();
  47. return strpos($name, '[') === FALSE ? $name : $name . '[]';
  48. }
  49. /**
  50. * Loads HTTP data.
  51. * @return void
  52. */
  53. public function loadHttpData()
  54. {
  55. $path = $this->getHtmlName(); // img_x or img['x']
  56. $path = strtr(str_replace(']', '', strpos($path, '[') === FALSE ? $path . '.x' : substr($path, 0, -2)), '.', '_');
  57. $this->setValue(/*Nette\*/ArrayTools::get($this->getForm()->getHttpData(), explode('[', $path)) !== NULL);
  58. }
  59. }