Skip to content

Commit

Permalink
PLANET-7489: Check number of columns in the P4 columns block (#2493)
Browse files Browse the repository at this point in the history
- Identify P4 column blocks using more than 4 columns
- Fix based on feedback
  • Loading branch information
mardelnet authored and comzeradd committed Jan 22, 2025
1 parent 49ec460 commit 9368da7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/BlockReportSearch/Block/BlockUsageTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "<span style='color: red;'>$cols - Fix needed!</span>";
}

return (string)$cols;
}

/**
* Block styles display.
*
Expand Down

0 comments on commit 9368da7

Please sign in to comment.