| 1 |
<?php |
| 2 |
defined('ABSPATH') || exit; |
| 3 |
|
| 4 |
/** |
| 5 |
* Module Name: Tab |
| 6 |
* Description: Display Tab content |
| 7 |
*/ |
| 8 |
class TB_Tab_Module extends Themify_Builder_Component_Module { |
| 9 |
|
| 10 |
|
| 11 |
public static function get_module_name():string { |
| 12 |
return __('Tab', 'themify'); |
| 13 |
} |
| 14 |
|
| 15 |
public static function get_module_icon():string { |
| 16 |
return 'layout-tab'; |
| 17 |
} |
| 18 |
|
| 19 |
public static function get_js_css():array { |
| 20 |
return array( |
| 21 |
'css' => 1, |
| 22 |
'js' => 1 |
| 23 |
); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* Render plain content for static content. |
| 29 |
* |
| 30 |
* @param array $module |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
public static function get_static_content(array $module):string { |
| 34 |
$mod_settings = $module['mod_settings']+ array( |
| 35 |
'mod_title_tab' => '', |
| 36 |
'tab_content_tab' => array() |
| 37 |
); |
| 38 |
$text ='' !== $mod_settings['mod_title_tab']?sprintf('<h3>%s</h3>', $mod_settings['mod_title_tab']): ''; |
| 39 |
if (!empty($mod_settings['tab_content_tab'])) { |
| 40 |
$text .= '<ul>'; |
| 41 |
foreach ($mod_settings['tab_content_tab'] as $content) { |
| 42 |
$text .= '<li>'; |
| 43 |
if ( ! empty( $content['title_tab'] ) ) { |
| 44 |
$text .= '<h4>' . $content['title_tab'] . '</h4>'; |
| 45 |
} |
| 46 |
if ( isset( $content['text_tab'] ) ) { |
| 47 |
$text .= $content['text_tab']; |
| 48 |
} else if ( ! empty( $content['builder_content'] ) && is_array( $content['builder_content'] ) ) { |
| 49 |
$text .= ThemifyBuilder_Data_Manager::_get_all_builder_text_content( $content['builder_content'] ); |
| 50 |
} |
| 51 |
$text .= '</li>'; |
| 52 |
} |
| 53 |
$text .= '</ul>'; |
| 54 |
} |
| 55 |
return $text; |
| 56 |
} |
| 57 |
|
| 58 |
public static function get_styling_image_fields() : array { |
| 59 |
return [ |
| 60 |
'bg_i' => '.ui .tab-nav li.current' |
| 61 |
]; |
| 62 |
} |
| 63 |
|
| 64 |
public static function get_translatable_fields( $module, $classname ) : array { |
| 65 |
$fields = parent::get_translatable_fields( $module, $classname ); |
| 66 |
if ( ! empty( $module['mod_settings']['mod_title_tab'] ) ) { |
| 67 |
$fields[] = [ |
| 68 |
'id' => 'mod_title_tab', |
| 69 |
'value' => $module['mod_settings']['mod_title_tab'], |
| 70 |
]; |
| 71 |
} |
| 72 |
if ( ! empty( $module['mod_settings']['tab_content_tab'] ) ) { |
| 73 |
foreach ( $module['mod_settings']['tab_content_tab'] as $row_index => $tab ) { |
| 74 |
if ( isset( $tab['title_tab'] ) ) { |
| 75 |
$fields[] = [ |
| 76 |
'id' => 'title_tab-' . $row_index, |
| 77 |
'value' => $tab['title_tab'], |
| 78 |
]; |
| 79 |
} |
| 80 |
if ( isset( $tab['text_tab'] ) ) { |
| 81 |
$fields[] = [ |
| 82 |
'id' => 'text_tab-' . $row_index, |
| 83 |
'value' => $tab['text_tab'], |
| 84 |
'type' => 'VISUAL', |
| 85 |
]; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
return $fields; |
| 91 |
} |
| 92 |
|
| 93 |
public static function translate_module( $module_data, $translations ) { |
| 94 |
foreach ( $translations as $item_key => $value ) { |
| 95 |
if ( $item_key === 'mod_title_tab' ) { |
| 96 |
$module_data['mod_settings']['mod_title_tab'] = $value; |
| 97 |
continue; |
| 98 |
} |
| 99 |
$parts = explode( '-', $item_key, 2 ); |
| 100 |
if ( count( $parts ) !== 2 ) { |
| 101 |
continue; |
| 102 |
} |
| 103 |
list( $field, $index ) = $parts; |
| 104 |
if ( isset( $module_data['mod_settings']['tab_content_tab'][ $index ][ $field ] ) ) { |
| 105 |
$module_data['mod_settings']['tab_content_tab'][ $index ][ $field ] = $value; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
return $module_data; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Returns a flat array of all nested modules |
| 114 |
*/ |
| 115 |
public static function get_nested_modules( array $data ) : array { |
| 116 |
$modules = []; |
| 117 |
if ( isset( $data['mod_settings']['tab_content_tab'][0]['builder_content'] ) ) { |
| 118 |
foreach ( $data['mod_settings']['tab_content_tab'] as $tab ) { |
| 119 |
foreach ( $tab['builder_content'] as $row ) { |
| 120 |
$modules = array_merge( $modules, Themify_Builder::_get_modules_recursive( $row ) ); |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
return $modules; |
| 126 |
} |
| 127 |
} |