AbstractTool.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Dcat\Admin\Tree;
  3. use Dcat\Admin\Actions\Action;
  4. use Dcat\Admin\Tree;
  5. abstract class AbstractTool extends Action
  6. {
  7. /**
  8. * @var Tree
  9. */
  10. protected $parent;
  11. /**
  12. * @var string
  13. */
  14. public $selectorPrefix = '.tree-tool-action-';
  15. /**
  16. * @var string
  17. */
  18. protected $style = 'btn btn-sm btn-primary';
  19. /**
  20. * @param Tree $parent
  21. *
  22. * @return void
  23. */
  24. public function setParent(Tree $parent)
  25. {
  26. $this->parent = $parent;
  27. }
  28. /**
  29. * @return string|void
  30. */
  31. protected function href()
  32. {
  33. }
  34. /**
  35. * @return string|void
  36. */
  37. public function html()
  38. {
  39. if ($href = $this->href()) {
  40. $this->disabledHandler = true;
  41. }
  42. $this->setHtmlAttribute([
  43. 'data-_key' => $this->key(),
  44. 'href' => $href ?: 'javascript:void(0);',
  45. 'class' => $this->style.' '.$this->elementClass(),
  46. ]);
  47. return "<a {$this->formatHtmlAttributes()}>{$this->title()}</a>";
  48. }
  49. }