ShowEditButton.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Admin\Section\Partial; |
| 4 | |
| 5 | use AC\Form\Element\Checkbox; |
| 6 | use AC\Renderable; |
| 7 | use AC\Settings\General; |
| 8 | use AC\Settings\Option\EditButton; |
| 9 | |
| 10 | class ShowEditButton implements Renderable { |
| 11 | |
| 12 | const OPTION_NAME = 'show_edit_button'; |
| 13 | |
| 14 | /** |
| 15 | * @var EditButton |
| 16 | */ |
| 17 | private $option; |
| 18 | |
| 19 | public function __construct() { |
| 20 | $this->option = new EditButton(); |
| 21 | } |
| 22 | |
| 23 | private function get_label() { |
| 24 | return sprintf( '%s %s', |
| 25 | sprintf( __( "Show %s button on table screen.", 'codepress-admin-columns' ), sprintf( '"%s"', __( 'Edit columns', 'codepress-admin-columns' ) ) ), |
| 26 | sprintf( __( "Default is %s.", 'codepress-admin-columns' ), '<code>' . __( 'on', 'codepress-admin-columns' ) . '</code>' ) |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return string |
| 32 | */ |
| 33 | public function render() { |
| 34 | $name = sprintf( '%s[%s]', General::NAME, $this->option->get_name() ); |
| 35 | |
| 36 | $checkbox = new Checkbox( $name ); |
| 37 | |
| 38 | $checkbox->set_options( [ '1' => $this->get_label() ] ) |
| 39 | ->set_value( $this->option->is_enabled() ? 1 : 0 ); |
| 40 | |
| 41 | return $checkbox->render(); |
| 42 | } |
| 43 | |
| 44 | } |