CascadeGroup.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. use Dcat\Admin\Form\Field;
  4. class CascadeGroup extends Field
  5. {
  6. /**
  7. * @var array
  8. */
  9. protected $dependency;
  10. /**
  11. * @var string
  12. */
  13. protected $hide = 'd-none';
  14. /**
  15. * CascadeGroup constructor.
  16. *
  17. * @param array $dependency
  18. */
  19. public function __construct(array $dependency)
  20. {
  21. $this->dependency = $dependency;
  22. }
  23. /**
  24. * @param Field $field
  25. *
  26. * @return bool
  27. */
  28. public function dependsOn(Field $field)
  29. {
  30. return $this->dependency['column'] == $field->column();
  31. }
  32. /**
  33. * @return int
  34. */
  35. public function index()
  36. {
  37. return $this->dependency['index'];
  38. }
  39. /**
  40. * @return void
  41. */
  42. public function visiable()
  43. {
  44. $this->hide = '';
  45. }
  46. /**
  47. * @return string
  48. */
  49. public function render()
  50. {
  51. return <<<HTML
  52. <div class="cascade-group {$this->dependency['class']} {$this->hide}">
  53. HTML;
  54. }
  55. /**
  56. * @return void
  57. */
  58. public function end()
  59. {
  60. $this->form->html('</div>')->plain();
  61. }
  62. }