HtmlAttributes.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Traits;
  3. /**
  4. * Html Attributes related functions
  5. *
  6. * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
  7. */
  8. trait HtmlAttributes
  9. {
  10. protected $htmlAttributes = [];
  11. public function getHtmlAttributes()
  12. {
  13. return $this->htmlAttributes;
  14. }
  15. public function addHtmlAttribute($key, $value)
  16. {
  17. $this->htmlAttributes[$key] = $value;
  18. return $this;
  19. }
  20. public function getHtmlAttribute($key)
  21. {
  22. return $this->htmlAttributes[$key];
  23. }
  24. public function deleteHtmlAttribute($key)
  25. {
  26. unset($this->htmlAttributes[$key]);
  27. return $this;
  28. }
  29. public function setHtmlAttributes(array $attribuetsList = [])
  30. {
  31. $this->htmlAttributes = $attribuetsList;
  32. return $this;
  33. }
  34. public function initOnClickVue($vueMethod = 'submitForm')
  35. {
  36. $stringClick = (string)$vueMethod . "(";
  37. $argsCount = 0;
  38. foreach (func_get_args() as $param)
  39. {
  40. if ($param === $vueMethod)
  41. {
  42. continue;
  43. }
  44. if ($argsCount > 0)
  45. {
  46. $stringClick .= ',';
  47. }
  48. $stringClick .= $param;
  49. $argsCount++;
  50. }
  51. $stringClick .= ")";
  52. $this->htmlAttributes['@click'] = $stringClick;
  53. return $this;
  54. }
  55. }