InlineStyle
1 day ago
ManageHeading
1 day ago
ManageValue
1 day ago
SaveHeading
1 day ago
Service
1 day ago
TableScreenRepository
1 day ago
AdminHeadStyle.php
1 day ago
ManageValueServiceFactory.php
1 day ago
PrimaryColumn.php
1 day ago
PrimaryColumnFactory.php
1 day ago
SaveHeadingFactory.php
1 day ago
Screen.php
1 day ago
ScreenTools.php
1 day ago
TableFormView.php
1 day ago
TablePreference.php
1 day ago
TableScreenCollection.php
1 day ago
TableScreenRepository.php
1 day ago
PrimaryColumn.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Table; |
| 6 | |
| 7 | use AC\Helper; |
| 8 | use AC\ListScreen; |
| 9 | use AC\ListTable\Comment; |
| 10 | use AC\PostType; |
| 11 | use AC\TableScreen\Media; |
| 12 | use AC\Type\ColumnId; |
| 13 | use WP_Post; |
| 14 | |
| 15 | class PrimaryColumn |
| 16 | { |
| 17 | private ListScreen $list_screen; |
| 18 | |
| 19 | public function __construct(ListScreen $list_screen) |
| 20 | { |
| 21 | $this->list_screen = $list_screen; |
| 22 | } |
| 23 | |
| 24 | public function set_primary_column(string $default): string |
| 25 | { |
| 26 | $default_column = $this->list_screen->get_column(new ColumnId($default)); |
| 27 | |
| 28 | $columns = $this->list_screen->get_columns(); |
| 29 | $column = $columns->first(); |
| 30 | |
| 31 | if (! $default_column && $column) { |
| 32 | $default = (string)$column->get_id(); |
| 33 | } |
| 34 | |
| 35 | $table_screen = $this->list_screen->get_table_screen(); |
| 36 | |
| 37 | // If actions column is present, set it as primary |
| 38 | foreach ($columns as $column) { |
| 39 | if ('column-actions' === $column->get_type()) { |
| 40 | $default = (string)$column->get_id(); |
| 41 | |
| 42 | if ($table_screen instanceof Media) { |
| 43 | // Add download button to the actions column |
| 44 | add_filter('media_row_actions', [$this, 'set_media_download_row_action'], 10, 2); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Set inline edit data if the default column (title) is not present |
| 50 | if ($table_screen instanceof PostType && 'title' !== $default) { |
| 51 | add_filter('page_row_actions', [$this, 'set_inline_edit_data'], 20, 2); |
| 52 | add_filter('post_row_actions', [$this, 'set_inline_edit_data'], 20, 2); |
| 53 | } |
| 54 | |
| 55 | // Remove inline edit action if the default column (author) is not present |
| 56 | if ($table_screen instanceof Comment && 'comment' !== $default) { |
| 57 | add_filter('comment_row_actions', [$this, 'remove_quick_edit_from_actions'], 20, 2); |
| 58 | } |
| 59 | |
| 60 | return $default; |
| 61 | } |
| 62 | |
| 63 | public function set_media_download_row_action(array $actions, WP_Post $post): array |
| 64 | { |
| 65 | $url = wp_get_attachment_url($post->ID); |
| 66 | |
| 67 | if (! $url) { |
| 68 | return $actions; |
| 69 | } |
| 70 | |
| 71 | $label = __('Download', 'codepress-admin-columns'); |
| 72 | |
| 73 | $actions['download'] = Helper\Html::create()->link( |
| 74 | $url, |
| 75 | $label, |
| 76 | [ |
| 77 | 'download' => '', |
| 78 | 'title' => $label, |
| 79 | ] |
| 80 | ); |
| 81 | |
| 82 | return $actions; |
| 83 | } |
| 84 | |
| 85 | public function set_inline_edit_data($actions, WP_Post $post) |
| 86 | { |
| 87 | get_inline_data($post); |
| 88 | |
| 89 | return $actions; |
| 90 | } |
| 91 | |
| 92 | public function remove_quick_edit_from_actions($actions) |
| 93 | { |
| 94 | unset($actions['quickedit']); |
| 95 | |
| 96 | return $actions; |
| 97 | } |
| 98 | |
| 99 | } |
| 100 |