A rock-solid recipe—100% aligned to the existing folder structure and build flow—for tacking on our ID column styling via LESS (so it survives every build.sh), fixing your build.sh permissions, and running everything from the HumHub root.
File
protected/modules/abcdirectory/views/admin/index.php
In the SpaceGridView::widget([ … 'columns' => [ … ] ]) array, prepend:
[
'attribute' => 'id',
'label' => Yii::t('AbcdirectoryModule.base', 'ID'),
'contentOptions' => ['class' => 'abcdirectory-space-id-column'],
],
so it becomes:
'columns' => [
[
'attribute' => 'id',
'label' => Yii::t('AbcdirectoryModule.base', 'ID'),
'contentOptions' => ['class' => 'abcdirectory-space-id-column'],
],
['class' => SpaceImageColumn::class],
['class' => SpaceTitleColumn::class],
// … the rest unchanged …
],
File
protected/modules/abcdirectory/resources/less/humhub.abcdirectory.admin.less
Append at the very bottom:
// ─── ID column styling ─────────────────────────────────────────
.abcdirectory-space-id-column {
width: 50px; // narrow fixed width
text-align: center;
font-weight: bold;
padding-right: 8px;
}
Why LESS? Every time you run
build.shyou regenerate../css/humhub.abcdirectory.admin.css, so injecting into the generated CSS will be overwritten. By putting it in the LESS source, it will persist.
build.sh permissions & rebuildFrom your HumHub root:
# 1) Make sure build.sh is executable
chmod +x protected/modules/abcdirectory/resources/less/build.sh
# 2) Run the LESS build
cd protected/modules/abcdirectory/resources/less
./build.sh
That will update:
protected/modules/abcdirectory/resources/css/humhub.abcdirectory.admin.css
with your new ID-column rule.
Still from your HumHub root:
rm -rf protected/runtime/cache/* protected/runtime/assets/*
Reload Admin → Spaces. You should now see a slim “ID” column at the left of every row.
| ID | Image | Name | Members | Visibility | … |
|---|
—where ID is the original space.id.
Here’s exactly what you need—using only the files you already have—so that an “Show Space ID column” checkbox appears in your module settings and actually shows/hides that narrow ID-column in your admin grid.
File:
protected/modules/abcdirectory/models/Configuration.php
What to do:
rules()--- a/models/Configuration.php
+++ b/models/Configuration.php
@@ class Configuration extends Model
public $spaceBreadcrumb = true;
public $getSpaceImageFromCategory = false;
+
+ /**
+ * Show the original space ID in the admin list
+ * @var bool
+ */
+ public $showSpaceIdColumn = false;
@@ public function rules(): array
- [['removeDefaultSpaceBrowser', 'removeDefaultSpaceDirectory', 'spaceBreadcrumb', 'getSpaceImageFromCategory'], 'boolean'],
+ [['removeDefaultSpaceBrowser', 'removeDefaultSpaceDirectory', 'spaceBreadcrumb', 'getSpaceImageFromCategory', 'showSpaceIdColumn'], 'boolean'],
@@ public function loadBySettings(): void
$this->spaceBreadcrumb = (bool)$this->settingsManager->get('spaceBreadcrumb', $this->spaceBreadcrumb);
$this->getSpaceImageFromCategory = (bool)$this->settingsManager->get('getSpaceImageFromCategory', $this->getSpaceImageFromCategory);
+ $this->showSpaceIdColumn = (bool)$this->settingsManager->get('showSpaceIdColumn', $this->showSpaceIdColumn);
@@ public function save(): bool
$this->settingsManager->set('spaceBreadcrumb', $this->spaceBreadcrumb);
$this->settingsManager->set('getSpaceImageFromCategory', $this->getSpaceImageFromCategory);
+ $this->settingsManager->set('showSpaceIdColumn', $this->showSpaceIdColumn);
File:
protected/modules/abcdirectory/views/config/index.php
What to do: Inside your form (for example, right after the “Space headers” section), add a new collapsible block:
<?= $form->beginCollapsibleFields(Yii::t('AbcdirectoryModule.config', 'Administration')) ?>
<?= $form->field($model, 'showSpaceIdColumn')
->checkbox()
->hint(Yii::t('AbcdirectoryModule.config', 'Toggle the ID column in the admin Spaces list')) ?>
<?= $form->endCollapsibleFields() ?>
Feel free to tweak the section title / hint to your taste.
File:
protected/modules/abcdirectory/views/admin/index.php
What to do:
Locate the GridView’s column array (around line 203). Above the first SpaceImageColumn, insert:
[
'attribute' => 'id',
'label' => Yii::t('AbcdirectoryModule.base', 'ID'),
'contentOptions' => ['class' => 'abcdirectory-space-id-column'],
'visible' => Yii::$app->getModule('abcdirectory')
->getConfiguration()
->showSpaceIdColumn,
],
Your final columns block will start like:
'columns' => [
[
'attribute' => 'id',
'label' => Yii::t('AbcdirectoryModule.base', 'ID'),
'contentOptions' => ['class' => 'abcdirectory-space-id-column'],
'visible' => Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn,
],
['class' => SpaceImageColumn::class],
['class' => SpaceTitleColumn::class],
// … the rest stays exactly as before …
],
build.shFile:
protected/modules/abcdirectory/resources/less/humhub.abcdirectory.admin.less
What to do: Append at the bottom:
// ─── ID column styling ─────────────────────────────────────────
.abcdirectory-space-id-column {
width: 50px; // narrow
text-align: center;
font-weight: bold;
padding-right: 8px;
}
Run everything from your HumHub root (never from /path/to/...)
# 1) Make sure the LESS build script is executable
chmod +x protected/modules/abcdirectory/resources/less/build.sh
# 2) Recompile the CSS
cd protected/modules/abcdirectory/resources/less
./build.sh
# 3) Clear Yii’s runtime & assets caches
cd "$(dirname "$PWD")"/../../.. # back to your HumHub root
rm -rf protected/runtime/cache/* protected/runtime/assets/*
space.id.To get the ID column to show in the top “classified” table (the one rendered via _tableHead.php / _tableSpaceRow.php), you need to add it in two places—your header partial and your row partial—guarded by the same showSpaceIdColumn config flag.
<th>File
protected/modules/abcdirectory/views/admin/_tableHead.php
Find the <tr> where your other <th>s live (around line 5). At the very start, prepend:
<?php if (Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn): ?>
<th class="abcdirectory-space-id-column">
<?= Yii::t('AbcdirectoryModule.base', 'ID') ?>
</th>
<?php endif; ?>
So it might look like:
<tr>
<?php if (Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn): ?>
<th class="abcdirectory-space-id-column">
<?= Yii::t('AbcdirectoryModule.base', 'ID') ?>
</th>
<?php endif; ?>
<th><?= Yii::t('AbcdirectoryModule.admin', 'Name / Sort order') ?></th>
<th><?= Yii::t('SpaceModule.base', 'Members') ?></th>
<th><?= Yii::t('SpaceModule.base', 'Visibility') ?></th>
<th></th>
</tr>
<td> with $space->idFile
protected/modules/abcdirectory/views/admin/_tableSpaceRow.php
At the top of the <tr> definition, after the opening <tr> tag but before you render the first cell, insert:
<?php if (Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn): ?>
<td class="abcdirectory-space-id-column">
<?= Html::encode($space->id) ?>
</td>
<?php endif; ?>
So your row partial will start roughly like:
<tr data-key="<?= $space->id ?>">
<?php if (Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn): ?>
<td class="abcdirectory-space-id-column">
<?= Html::encode($space->id) ?>
</td>
<?php endif; ?>
<td>
<!-- existing code for title/sort-order… -->
</td>
<td><?= $memberCount ?></td>
<td><?= /* visibility label… */ ?></td>
<td><?= SpaceAdminMenu::widget([...]) ?></td>
</tr>
That ensures your “ID” both has a header and actual cells in the top table.
You already added in
protected/modules/abcdirectory/resources/less/humhub.abcdirectory.admin.less
.abcdirectory-space-id-column {
width: 50px;
text-align: center;
font-weight: bold;
padding-right: 8px;
}
So after you rebuilt (and cleared caches), that style will apply to both the top table and the unclassified grid.
(from your HumHub root)
chmod +x protected/modules/abcdirectory/resources/less/build.sh
cd protected/modules/abcdirectory/resources/less
./build.sh
cd ../../../.. # back to HumHub root
rm -rf protected/runtime/cache/* protected/runtime/assets/*
Now when you check the “Show Space ID column” box and reload Admin → Spaces, you should see a narrow “ID” column in both the top (classified) and bottom (unclassified) tables.
For a better look and feel and for practical usability reasons we like to integrate the Category ID's too
To show an ID cell for your categories as well, you need to add the same conditional <td> you did for spaces into your category-row partial. Here’s exactly what to do:
You’ve already got the <th> in _tableHead.php wrapped in the showSpaceIdColumn check, so both category and space tables share that “ID” column header.
File:
protected/modules/abcdirectory/views/admin/_tableCategoryRow.php
Import Html at the top (if not already):
<?php use yii\helpers\Html; ?>
Find the opening of your <tr> block—somewhere like:
<tr data-key="<?= $category->id ?>">
Immediately after that <tr> line, insert:
<?php if (Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn): ?>
<td class="abcdirectory-space-id-column">
<?= Html::encode($category->id) ?>
</td>
<?php endif; ?>
So your _tableCategoryRow.php will start like:
<?php use yii\helpers\Html; ?>
<tr data-key="<?= $category->id ?>">
<?php if (Yii::$app->getModule('abcdirectory')->getConfiguration()->showSpaceIdColumn): ?>
<td class="abcdirectory-space-id-column">
<?= Html::encode($category->id) ?>
</td>
<?php endif; ?>
<td>
<!-- existing category title / sort‐order markup -->
</td>
<!-- … other columns (e.g. member counts, visibility icons) … -->
</tr>
From your HumHub root:
chmod +x protected/modules/abcdirectory/resources/less/build.sh
cd protected/modules/abcdirectory/resources/less
./build.sh
cd ../../../.. # back to HumHub root
rm -rf protected/runtime/cache/* protected/runtime/assets/*
Now, when “Show Space ID column” is checked, you’ll get that narrow ID cell for both categories and spaces in the top table—keeping your columns aligned and your look consistent.