From 9368da7ab4bb0d08f84a4627491ed0a1b6b1f4fc Mon Sep 17 00:00:00 2001 From: Pedro Figueroa <59029273+mardelnet@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:20:54 +0100 Subject: [PATCH] PLANET-7489: Check number of columns in the P4 columns block (#2493) - Identify P4 column blocks using more than 4 columns - Fix based on feedback --- .../Block/BlockUsageTable.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/BlockReportSearch/Block/BlockUsageTable.php b/src/BlockReportSearch/Block/BlockUsageTable.php index 4230f80e9c..fd039f06c6 100644 --- a/src/BlockReportSearch/Block/BlockUsageTable.php +++ b/src/BlockReportSearch/Block/BlockUsageTable.php @@ -272,6 +272,12 @@ public function get_columns(): ?array 'post_status' => 'Status', ]; + // This is a temporary fix to identify problems with the columns migrated here: + // https://jira.greenpeace.org/browse/PLANET-7489 + if (isset($_GET['name']) && $_GET['name'] === 'planet4-blocks/columns') { + $default_columns['block_cols'] = 'Columns'; + } + $this->columns = array_merge( [ $this->group_by => $default_columns[ $this->group_by ] ], $default_columns @@ -487,6 +493,33 @@ public function column_block_attrs($item): string ); } + /** + * Add the number of columns to the table. + * + * This is a temporary fix to identify problems with the columns migrated here: + * https://jira.greenpeace.org/browse/PLANET-7489 + * We need this function to identify P4 columns blocks using more than 4 columns. + * + * @param array $item Item. + * @phpcs:disable SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint + */ + public function column_block_cols($item): string + { + $content = $item['block_attrs'] ?? null; + + if (empty($content)) { + return ''; + } + + $cols = $content['columns'] ? count($content['columns']) : '0'; + + if ($cols > 4) { + return "$cols - Fix needed!"; + } + + return (string)$cols; + } + /** * Block styles display. *