class-metabox-collapsible.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Generates the HTML for a metabox tab.
  9. */
  10. class WPSEO_Metabox_Collapsible implements WPSEO_Metabox_Tab {
  11. /**
  12. * The collapsible's unique identifier.
  13. *
  14. * @var string
  15. */
  16. private $name;
  17. /**
  18. * The content to be displayed inside the collapsible.
  19. *
  20. * @var string
  21. */
  22. private $content;
  23. /**
  24. * The label.
  25. *
  26. * @var string
  27. */
  28. private $link_content;
  29. /**
  30. * Constructor.
  31. *
  32. * @param string $name The name of the tab, used as an identifier in the html.
  33. * @param string $content The tab content.
  34. * @param string $link_content The text content of the tab link.
  35. */
  36. public function __construct( $name, $content, $link_content ) {
  37. $this->name = $name;
  38. $this->content = $content;
  39. $this->link_content = $link_content;
  40. }
  41. /**
  42. * Returns the html for the tab link.
  43. *
  44. * @return string
  45. */
  46. public function link() {
  47. return $this->link_content;
  48. }
  49. /**
  50. * Returns the html for the tab content.
  51. *
  52. * @return string
  53. */
  54. public function content() {
  55. $collapsible_paper = new WPSEO_Paper_Presenter(
  56. $this->link(),
  57. null,
  58. [
  59. 'content' => $this->content,
  60. 'collapsible' => true,
  61. 'class' => 'metabox wpseo-form wpseo-collapsible-container',
  62. 'paper_id' => 'collapsible-' . $this->name,
  63. ]
  64. );
  65. return $collapsible_paper->get_output();
  66. }
  67. /**
  68. * Returns the collapsible's unique identifier.
  69. *
  70. * @return string
  71. */
  72. public function get_name() {
  73. return $this->name;
  74. }
  75. }