PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.4.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.4.0
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Editors / BlockEditor / Blocks / ToC.php

ToC.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 3.4.0, at includes/Editors/BlockEditor/Blocks/ToC.php

81 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Editors\BlockEditor\Blocks;
4
5 use WPDeveloper\BetterDocs\Editors\BlockEditor\Block;
6
7 class ToC extends Block {
8 public function get_name() {
9 return 'table-of-contents';
10 }
11
12 public function get_default_attributes() {
13 return [
14 'blockId' => '',
15 'toc_supported_tags' => [
16 [
17 'value' => 1,
18 'label' => 'H1'
19 ],
20 [
21 'value' => 2,
22 'label' => 'H2'
23 ],
24 [
25 'value' => 3,
26 'label' => 'H3'
27 ],
28 [
29 'value' => 4,
30 'label' => 'H4'
31 ],
32 [
33 'value' => 5,
34 'label' => 'H5'
35 ]
36 ],
37 'toc_list_heirarchy' => true,
38 'toc_list_number' => true,
39 'toc_collapsible_small_devices' => true,
40 'toc_title_text' => 'Table Of Contents'
41 ];
42 }
43
44 public function render( $attributes, $content ) {
45 $this->views( 'widgets/toc' );
46 }
47
48 public function view_params() {
49 $htags = [];
50
51 if ( ! empty( $this->attributes['toc_supported_tags'] ) ) {
52 $htags = array_map( function ( $item ) {
53 return $item['value'];
54 }, $this->attributes['toc_supported_tags'] );
55 }
56
57 $toc_setting = [
58 'htags' => $htags,
59 'hierarchy' => $this->attributes['toc_list_heirarchy'],
60 'list_number' => $this->attributes['toc_list_number']
61 ];
62
63 //set TOC data in Transient, whenever TOC(block) is called.
64 set_transient( 'betterdocs_toc_setting', $toc_setting );
65
66 $htags = implode( ',', $htags );
67
68 $attributes = betterdocs()->template_helper->get_html_attributes( [
69 'htags' => $htags,
70 'hierarchy' => $this->attributes['toc_list_heirarchy'],
71 'list_number' => $this->attributes['toc_list_number'],
72 'collapsible_on_mobile' => $this->attributes['toc_collapsible_small_devices'],
73 'toc_title' => $this->attributes['toc_title_text']
74 ] );
75
76 return [
77 'attributes' => $attributes
78 ];
79 }
80 }
81