You are here

public function DynamicLayout::deleteColumn in Dynamic Layouts 8

Delete a specific column from the layout.

Parameters

int $row_id: The row number we need to delete the column from.

int $column_id: The column id we need to delete.

Overrides DynamicLayoutInterface::deleteColumn

File

src/Entity/DynamicLayout.php, line 573

Class

DynamicLayout
Defines the DynamicLayout entity.

Namespace

Drupal\dynamic_layouts\Entity

Code

public function deleteColumn($row_id, $column_id) {
  $updated_row = $this
    ->getRowById($row_id);
  $columns = $updated_row[Constants::COLUMNS];

  /** @var \Drupal\dynamic_layouts\DynamicLayoutSettingsInterface $settings */
  $calculated_column_width_number = NULL;
  if ($settings = \Drupal::entityTypeManager()
    ->getStorage(Constants::DYNAMIC_LAYOUT_SETTINGS)
    ->load(Constants::SETTINGS)) {
    $calculated_column_width_number = $this
      ->calculateColumnWidth($columns, $settings, 'deleted');
  }

  // Loop over the columns and set the updated column.
  foreach ($columns as $key => $column) {
    if ($column[Constants::COLUMN_ID] == $column_id) {
      unset($columns[$key]);
      continue;
    }
    if ($calculated_column_width_number && !isset($column[Constants::CUSTOM_COLUMN_WIDTH_NUMBER])) {
      $columns[$key][Constants::COLUMN_WIDTH_NUMBER] = $calculated_column_width_number;
    }
  }

  // Loop over the rows and find the corresponding row number.
  $rows = $this
    ->getRows();
  foreach ($rows as $key => $row) {
    if ($row[Constants::ROW_ID] == $row_id) {
      $rows[$key][Constants::COLUMNS] = $columns;
    }
  }
  $this->regions = serialize($rows);
}