forked from elementor/elementor
-
Notifications
You must be signed in to change notification settings - Fork 0
table widget #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Mchris-hub
wants to merge
7
commits into
hein-obox:main
Choose a base branch
from
Mchris-hub:christian/table-widget-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
−6
Draft
table widget #2
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ae22572
table widget
Mchris-hub f0a8017
changing file and class name, fixing typos
Mchris-hub 2664131
adding javascript,fixing row's creations issues
Mchris-hub 7d0aabc
renaming the repeater from list to row, renaming the 'list' variables…
Mchris-hub ff5fd7f
restructuring the rows, adding javascript
Mchris-hub 3d53eea
removing defaults fields values, adding some spacing, deleting useles…
Mchris-hub f121449
adding the style tab and it controls
Mchris-hub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,324 @@ | ||
<?php | ||
namespace Elementor; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
use Elementor\Core\Kits\Documents\Tabs\Global_Colors; | ||
use Elementor\Core\Kits\Documents\Tabs\Global_Typography; | ||
|
||
|
||
/** | ||
* Elementor table widget. | ||
* | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
class Widget_Table extends Widget_Base { | ||
|
||
/** | ||
* Get widget name. | ||
* | ||
* Retrieve table widget name. | ||
* | ||
* @since 1.0.0 | ||
* @access public | ||
* | ||
* @return string Widget name. | ||
*/ | ||
public function get_name() { | ||
return 'table'; | ||
} | ||
|
||
/** | ||
* Get widget title. | ||
* | ||
* Retrieve table widget title. | ||
* | ||
* @since 1.0.0 | ||
* @access public | ||
* | ||
* @return string Widget title. | ||
*/ | ||
public function get_title() { | ||
return esc_html__( 'Table', 'elementor' ); | ||
} | ||
|
||
/** | ||
* Get widget icon. | ||
* | ||
* Retrieve table widget icon. | ||
* | ||
* @since 1.0.0 | ||
* @access public | ||
* | ||
* @return string Widget icon. | ||
*/ | ||
public function get_icon() { | ||
return 'eicon-table'; | ||
} | ||
|
||
/** | ||
* Get widget categories. | ||
* | ||
* Retrieve the list of categories the table widget belongs to. | ||
* | ||
* Used to determine where to display the widget in the editor. | ||
* | ||
* @since 2.0.0 | ||
* @access public | ||
* | ||
* @return array Widget categories. | ||
*/ | ||
public function get_categories() { | ||
return [ 'basic' ]; | ||
} | ||
|
||
/** | ||
* Get widget keywords. | ||
* | ||
* Retrieve the list of keywords the widget belongs to. | ||
* | ||
* @since 2.1.0 | ||
* @access public | ||
* | ||
* @return array Widget keywords. | ||
*/ | ||
public function get_keywords() { | ||
return [ 'table']; | ||
} | ||
|
||
/** | ||
* Register table widget controls. | ||
* | ||
* Adds different input fields to allow the user to change and customize the widget settings. | ||
* | ||
* @since 3.1.0 | ||
* @access protected | ||
*/ | ||
protected function register_controls() { | ||
|
||
$this->start_controls_section( | ||
'content_section', | ||
[ | ||
'label' => esc_html__( 'Table content', 'elementor' ), | ||
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'show_title', | ||
[ | ||
'label' => esc_html__( 'Show Columns Titles', 'elementor' ), | ||
'type' => \Elementor\Controls_Manager::SWITCHER, | ||
'label_on' => esc_html__( 'Show', 'elementor' ), | ||
'label_off' => esc_html__( 'Hide', 'elementor' ), | ||
'return_value' => 'yes', | ||
'default' => 'yes', | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'column_one', | ||
[ | ||
'label' => esc_html__( 'Title column 1', 'elementor' ), | ||
'type' => Controls_Manager::TEXT, | ||
'label_block' => true, | ||
'placeholder' => esc_html__( 'Enter column title', 'elementor' ), | ||
'dynamic' => [ | ||
'active' => true, | ||
], | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'column_two', | ||
[ | ||
'label' => esc_html__( 'Title column 2', 'elementor' ), | ||
'type' => Controls_Manager::TEXT, | ||
'label_block' => true, | ||
'placeholder' => esc_html__( 'Enter column title', 'elementor' ), | ||
'dynamic' => [ | ||
'active' => true, | ||
], | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'column_three', | ||
[ | ||
'label' => esc_html__( 'Title column 3', 'elementor' ), | ||
'type' => Controls_Manager::TEXT, | ||
'label_block' => true, | ||
'placeholder' => esc_html__( 'Enter column title', 'elementor' ), | ||
'dynamic' => [ | ||
'active' => true, | ||
], | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'rows', | ||
[ | ||
'label' => esc_html__( "Content rows", 'elementor' ), | ||
'show_label' => true, | ||
'type' => \Elementor\Controls_Manager::REPEATER, | ||
'fields' => [ | ||
[ | ||
'name' => 'column_content_one', | ||
'label' => esc_html__( 'Content column 1', 'elementor' ), | ||
'type' => \Elementor\Controls_Manager::TEXT, | ||
'label_block' => false, | ||
], | ||
[ | ||
'name' => 'column_content_two', | ||
'label' => esc_html__( 'column content 2', 'elementor' ), | ||
'type' => \Elementor\Controls_Manager::TEXT, | ||
'label_block' => false, | ||
], | ||
[ | ||
'name' => 'column_content_three', | ||
'label' => esc_html__( 'column content 3', 'elementor' ), | ||
'type' => \Elementor\Controls_Manager::TEXT, | ||
'label_block' => false, | ||
], | ||
], | ||
'title_field' => esc_html__( 'row', 'elementor'), | ||
|
||
] | ||
); | ||
|
||
|
||
$this->end_controls_section(); | ||
|
||
$this->start_controls_section( | ||
'style_section', | ||
[ | ||
'label' => esc_html__( 'Style', 'elementor' ), | ||
'tab' => \Elementor\Controls_Manager::TAB_STYLE, | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'table_head_color', | ||
[ | ||
'label' => esc_html__( 'Table head Color', 'elementor' ), | ||
'type' => \Elementor\Controls_Manager::COLOR, | ||
'global' => [ | ||
'default' => Global_Colors::COLOR_TEXT, | ||
], | ||
'selectors' => [ | ||
'{{WRAPPER}} .table_head' => 'color: {{VALUE}};', | ||
], | ||
] | ||
); | ||
|
||
$this->add_control( | ||
'table_head_background_color', | ||
[ | ||
'label' => esc_html__( 'Table head background Color', 'elementor' ), | ||
'type' => \Elementor\Controls_Manager::COLOR, | ||
'global' => [ | ||
'default' => Global_Colors::COLOR_ACCENT, | ||
], | ||
'selectors' => [ | ||
'{{WRAPPER}} .table_head' => 'background-color: {{VALUE}};', | ||
], | ||
] | ||
); | ||
|
||
$this->add_group_control( | ||
\Elementor\Group_Control_Typography::get_type(), | ||
[ | ||
'name' => 'sub_heading_typography', | ||
'global' => [ | ||
'default' => \Elementor\Core\Kits\Documents\Tabs\Global_Typography::TYPOGRAPHY_SECONDARY, | ||
], | ||
'selector' => '{{WRAPPER}} .table_head', | ||
] | ||
); | ||
|
||
$this->add_group_control( | ||
\Elementor\Group_Control_Border::get_type(), | ||
[ | ||
'name' => 'border', | ||
'selector' => '{{WRAPPER}} .table_head', | ||
] | ||
); | ||
|
||
$this->end_controls_section(); | ||
|
||
} | ||
|
||
/** | ||
* Render table widget output on the frontend. | ||
* | ||
* Written in PHP and used to generate the final HTML. | ||
* | ||
* @since 1.0.0 | ||
* @access protected | ||
*/ | ||
|
||
protected function render() { | ||
$settings = $this->get_settings_for_display(); | ||
|
||
echo '<table id="table">'; | ||
if ( 'yes' === $settings['show_title'] ) { | ||
echo '<thead class="table_head">'; | ||
echo '<tr>'; | ||
echo '<th>' . $settings['column_one'] . '</th>'; | ||
echo '<th>' . $settings['column_two'] . '</th>'; | ||
echo '<th>' . $settings['column_three'] . '</th>'; | ||
echo '</tr>'; | ||
echo '</thead>'; | ||
} | ||
|
||
if ( $settings['rows'] ) { | ||
echo '<tbody>'; | ||
$rows = $settings['rows']; | ||
for ($i=0; $i <= count($rows) - 1; $i++) { | ||
echo '<tr>'; | ||
echo '<td class="elementor-repeater-item-' . esc_attr( $rows[$i]['_id'] ) . '">' .$rows[$i]['column_content_one'] . '</td>'; | ||
echo '<td class="elementor-repeater-item-' . esc_attr( $rows[$i]['_id'] ) . '">' .$rows[$i]['column_content_two'] . '</td>'; | ||
echo '<td class="elementor-repeater-item-' . esc_attr( $rows[$i]['_id'] ) . '">' .$rows[$i]['column_content_three'] . '</td>'; | ||
echo '<tr>'; | ||
} | ||
|
||
echo '</tbody>'; | ||
}; | ||
echo '</table>'; | ||
} | ||
|
||
|
||
protected function content_template() { | ||
?> | ||
|
||
<table> | ||
<# if ( 'yes' === settings.show_title ) { #> | ||
<thead class="table_head"> | ||
<tr> | ||
<th>{{{ settings.column_one }}}</th> | ||
<th>{{{ settings.column_two }}}</th> | ||
<th>{{{ settings.column_three }}}</th> | ||
</tr> | ||
</thead> | ||
<# } #> | ||
|
||
<# if ( settings.rows.length ) { #> | ||
<tbody> | ||
<# let rows = settings.rows #> | ||
<# for( let i = 0; i <= rows.length - 1; i++ ){ #> | ||
<tr> | ||
<td class="elementor-repeater-item-{{ rows[i]._id }}">{{{ rows[i].column_content_one }}}</td> | ||
<td class="elementor-repeater-item-{{ rows[i]._id }}">{{{ rows[i].column_content_two }}}</td> | ||
<td class="elementor-repeater-item-{{ rows[i]._id }}">{{{ rows[i].column_content_three }}}</td> | ||
</tr> | ||
<# } #> | ||
</tbody> | ||
<# } #> | ||
</table> | ||
<?php | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use labels from Trello.
Using the correct lowercase vs uppercase is important. You can't mix it randomly.