Total Complexity | 8 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait HasShortcodes |
||
8 | { |
||
9 | |||
10 | /** |
||
11 | * Field name. |
||
12 | * |
||
13 | * @return string |
||
14 | */ |
||
15 | 3 | public function shortcodesKey(): string |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * Shortcodes map. |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | 1 | public function shortcodesMap(): array |
|
32 | 1 | // 'image' => ImageWithCaption::class, |
|
33 | 1 | ]; |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * Restore shortcode data. |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | 2 | public function shortcodesData(): array |
|
42 | { |
||
43 | 2 | $data = null; |
|
44 | 2 | if (($shortcodes = $this->{$this->shortcodesKey()}) && is_string($shortcodes)) { |
|
45 | 2 | $data = json_decode($shortcodes, true); |
|
46 | } |
||
47 | |||
48 | 2 | return is_array($data) ? $data : []; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Add shortcodes to content. |
||
53 | * |
||
54 | * @param string $data |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 2 | public function getDataWithShortcodes(string $data = ''): string |
|
64 | } |
||
65 | } |
||
66 |