public function DynamicLayout::addRow in Dynamic Layouts 8
Add a row to the layout.
Overrides DynamicLayoutInterface::addRow
File
- src/
Entity/ DynamicLayout.php, line 358
Class
- DynamicLayout
- Defines the DynamicLayout entity.
Namespace
Drupal\dynamic_layouts\EntityCode
public function addRow() {
$rows = $this
->getRows();
$column_count = 1;
/** @var \Drupal\dynamic_layouts\DynamicLayoutSettingsInterface $settings */
$last_column_class = '';
$column_width_prefix = '';
if ($settings = \Drupal::entityTypeManager()
->getStorage(Constants::DYNAMIC_LAYOUT_SETTINGS)
->load(Constants::SETTINGS)) {
$column_classes = array_keys($settings
->getFrontendColumnClasses());
$last_column_class = end($column_classes);
$column_width_prefix = $settings
->getColumnPrefix();
}
$row_id = uniqid();
$columns = [];
for ($i = 1; $i <= $column_count; $i++) {
$column_id = uniqid();
$edit_column = $this
->getEditColumnLink($this
->id(), $row_id, $column_id);
$delete_column = $this
->getDeleteColumnLink($this
->id(), $row_id, $column_id);
$columns[] = [
Constants::EDIT_COLUMN => $edit_column,
Constants::DELETE_COLUMN => $delete_column,
Constants::COLUMN_ID => $column_id,
Constants::COLUMN_WIDTH_NUMBER => $last_column_class,
Constants::COLUMN_WIDTH_PREFIX => $column_width_prefix,
Constants::DEFAULT_COLUMN_CLASS => $this->default_column_class,
Constants::CUSTOM_COLUMN_CLASSES => [],
Constants::COLUMN_NAME => '',
Constants::REGION_NAME => 'r' . $row_id . 'c' . $column_id,
Constants::ADMIN_COLUMN_CLASSES => [
Constants::DYNAMIC_LAYOUT_COLUMN,
],
];
}
// Add new row.
$rows[] = [
Constants::ROW_ID => $row_id,
'admin_row_classes' => [
'dynamic-layout-row',
],
Constants::DEFAULT_ROW_CLASS => $this->default_row_class,
Constants::CUSTOM_ROW_CLASSES => [],
Constants::COLUMNS => $columns,
];
$this->regions = serialize($rows);
}