| @@ -7,13 +7,16 @@ | ||
| 7 | 7 | * @author Tobias Bäthge |
| 8 | 8 | * @since 1.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +declare(strict_types=1); | |
| 12 | + | |
| 11 | 13 | // Prohibit direct script loading. |
| 12 | 14 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 | 15 | |
| 14 | 16 | /** |
| 15 | 17 | * Add Table View class |
| 18 | + * | |
| 16 | 19 | * @package TablePress |
| 17 | 20 | * @subpackage Views |
| 18 | 21 | * @author Tobias Bäthge |
| 19 | 22 | * @since 1.0.0 |
| @@ -20,39 +23,42 @@ | ||
| 20 | 23 | */ |
| 21 | 24 | class TablePress_Add_View extends TablePress_View { |
| 22 | 25 | |
| 23 | 26 | /** |
| 24 | - * Set up the view with data and do things that are specific for this view. | |
| 27 | + * Sets up the view with data and does things that are specific for this view. | |
| 25 | 28 | * |
| 26 | 29 | * @since 1.0.0 |
| 27 | 30 | * |
| 28 | - * @param string $action Action for this view. | |
| 29 | - * @param array $data Data for this view. | |
| 31 | + * @param string $action Action for this view. | |
| 32 | + * @param array<string, mixed> $data Data for this view. | |
| 30 | 33 | */ |
| 31 | - public function setup( $action, array $data ) { | |
| 34 | + #[\Override] | |
| 35 | + public function setup( /* string */ $action, array $data ) /* : void */ { | |
| 36 | + // Don't use type hints in the method declaration to prevent PHP errors, as the method is inherited. | |
| 37 | + | |
| 32 | 38 | parent::setup( $action, $data ); |
| 33 | 39 | |
| 34 | - $this->admin_page->enqueue_script( 'add', array( 'jquery-core' ) ); | |
| 40 | + $this->add_text_box( 'no-javascript', array( $this, 'textbox_no_javascript' ), 'header' ); | |
| 35 | 41 | |
| 36 | 42 | $this->process_action_messages( array( |
| 37 | 43 | 'error_add' => __( 'Error: The table could not be added.', 'tablepress' ), |
| 38 | 44 | ) ); |
| 39 | 45 | |
| 46 | + TablePress::enqueue_script( 'add' ); | |
| 47 | + | |
| 40 | 48 | $this->add_text_box( 'head', array( $this, 'textbox_head' ), 'normal' ); |
| 41 | - $this->add_meta_box( 'add-table', __( 'Add New Table', 'tablepress' ), array( $this, 'postbox_add_table' ), 'normal' ); | |
| 42 | - $this->data['submit_button_caption'] = __( 'Add Table', 'tablepress' ); | |
| 43 | - $this->add_text_box( 'submit', array( $this, 'textbox_submit_button' ), 'submit' ); | |
| 49 | + $this->add_text_box( 'add-table', array( $this, 'textbox_add_table' ), 'normal' ); | |
| 44 | 50 | } |
| 45 | 51 | |
| 46 | 52 | /** |
| 47 | - * Print the screen head text. | |
| 53 | + * Prints the screen head text. | |
| 48 | 54 | * |
| 49 | 55 | * @since 1.0.0 |
| 50 | 56 | * |
| 51 | - * @param array $data Data for this screen. | |
| 52 | - * @param array $box Information about the text box. | |
| 57 | + * @param array<string, mixed> $data Data for this screen. | |
| 58 | + * @param array<string, mixed> $box Information about the text box. | |
| 53 | 59 | */ |
| 54 | - public function textbox_head( array $data, array $box ) { | |
| 60 | + public function textbox_head( array $data, array $box ): void { | |
| 55 | 61 | ?> |
| 56 | 62 | <p> |
| 57 | 63 | <?php _e( 'To add a new table, enter its name, a description (optional), and the number of rows and columns into the form below.', 'tablepress' ); ?> |
| 58 | 64 | </p> |
| @@ -62,40 +68,16 @@ | ||
| 62 | 68 | <?php |
| 63 | 69 | } |
| 64 | 70 | |
| 65 | 71 | /** |
| 66 | - * Print the content of the "Add New Table" post meta box. | |
| 72 | + * Prints the content of the "Add New Table" text box. | |
| 67 | 73 | * |
| 68 | - * @since 1.0.0 | |
| 74 | + * @since 3.0.0 | |
| 69 | 75 | * |
| 70 | - * @param array $data Data for this screen. | |
| 71 | - * @param array $box Information about the meta box. | |
| 76 | + * @param array<string, mixed> $data Data for this screen. | |
| 77 | + * @param array<string, mixed> $box Information about the text box. | |
| 72 | 78 | */ |
| 73 | - public function postbox_add_table( array $data, array $box ) { | |
| 74 | - ?> | |
| 75 | - <div class="form-wrap"> | |
| 76 | - <div class="form-field"> | |
| 77 | - <label for="table-name"><?php _e( 'Table Name', 'tablepress' ); ?>:</label> | |
| 78 | - <input type="text" name="table[name]" id="table-name" class="placeholder placeholder-active" value="<?php esc_attr_e( 'Enter Table Name here', 'tablepress' ); ?>" /> | |
| 79 | - <p><?php _e( 'The name or title of your table.', 'tablepress' ); ?></p> | |
| 80 | - </div> | |
| 81 | - <div class="form-field"> | |
| 82 | - <label for="table-description"><?php _e( 'Description', 'tablepress' ); ?> <?php _e( '(optional)', 'tablepress' ); ?>:</label> | |
| 83 | - <textarea name="table[description]" id="table-description" class="placeholder placeholder-active" rows="4"><?php echo esc_textarea( __( 'Enter Description here', 'tablepress' ) ); ?></textarea> | |
| 84 | - <p><?php _e( 'A description of the contents of your table.', 'tablepress' ); ?></p> | |
| 85 | - </div> | |
| 86 | - <div class="form-field form-required form-field-numbers-only form-field-small"> | |
| 87 | - <label for="table-rows"><?php _e( 'Number of Rows', 'tablepress' ); ?>:</label> | |
| 88 | - <input type="number" name="table[rows]" id="table-rows" title="<?php esc_attr_e( 'This field must contain a positive number.', 'tablepress' ); ?>" value="5" min="1" max="99999" maxlength="5" required /> | |
| 89 | - <p><?php _e( 'The number of rows in your table.', 'tablepress' ); ?></p> | |
| 90 | - </div> | |
| 91 | - <div class="form-field form-required form-field-numbers-only form-field-small"> | |
| 92 | - <label for="table-columns"><?php _e( 'Number of Columns', 'tablepress' ); ?>:</label> | |
| 93 | - <input type="number" name="table[columns]" id="table-columns" title="<?php esc_attr_e( 'This field must contain a positive number.', 'tablepress' ); ?>" value="5" min="1" max="99999" maxlength="5" required /> | |
| 94 | - <p><?php _e( 'The number of columns in your table.', 'tablepress' ); ?></p> | |
| 95 | - </div> | |
| 96 | - <div class="clear"></div> | |
| 97 | - </div> | |
| 98 | - <?php | |
| 79 | + public function textbox_add_table( array $data, array $box ): void { | |
| 80 | + echo '<div id="tablepress-add-screen"></div>'; | |
| 99 | 81 | } |
| 100 | 82 | |
| 101 | 83 | } // class TablePress_Add_View |