AbstractTool.php 1.3 KB

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