You are here

private function DynamicLayout::calculateColumnWidth in Dynamic Layouts 8

2 calls to DynamicLayout::calculateColumnWidth()
DynamicLayout::addColumn in src/Entity/DynamicLayout.php
Add a column to a row.
DynamicLayout::deleteColumn in src/Entity/DynamicLayout.php
Delete a specific column from the layout.

File

src/Entity/DynamicLayout.php, line 670

Class

DynamicLayout
Defines the DynamicLayout entity.

Namespace

Drupal\dynamic_layouts\Entity

Code

private function calculateColumnWidth($columns, DynamicLayoutSettingsInterface $settings, $action) {
  if (!$settings) {
    return NULL;
  }
  if (!$columns) {
    return NULL;
  }

  // Count the column's that dont have a custom column width number.
  $column_counter = 0;
  foreach ($columns as $column) {
    if (!isset($column[Constants::CUSTOM_COLUMN_WIDTH_NUMBER])) {
      $column_counter++;
    }
  }

  // Get the frontend library & column count and add/remove 1.
  $column_count = $column_counter + 1;
  if ($action == 'deleted') {
    $column_count = $column_counter - 1;
  }

  // Convert to integer, just to be sure.
  $grid_column_count = \intval($settings
    ->getGridColumnCount());

  // Divide the column count by grid column count.
  return \round($grid_column_count / $column_count);
}