Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customize title column's label #2318

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Http/Controllers/Admin/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ abstract class ModuleController extends Controller
*/
protected $titleColumnKey = 'title';

/**
* Label of the index column to use as name column.
*
* @var string
*/
protected $titleColumnLabel = 'Title';

/**
* Name of the index column to use as identifier column.
*
Expand All @@ -245,6 +252,13 @@ abstract class ModuleController extends Controller
*/
protected $titleFormKey;

/**
* Label of the title field in forms.
*
* @var string
*/
protected $titleFormLabel = 'Title';

/**
* Feature field name if the controller is using the feature route (defaults to "featured").
*
Expand Down Expand Up @@ -643,6 +657,30 @@ protected function setTitleColumnKey(string $titleColumnKey): void
$this->titleColumnKey = $titleColumnKey;
}

/**
* Sets the label to use for title column, defaults to `Title`.
*/
protected function setTitleColumnLabel(string $titleColumnLabel): void
{
$this->titleColumnLabel = $titleColumnLabel;
}

/**
* Sets the field to use as title in forms, defaults to `title`.
*/
protected function setTitleFormKey(string $titleFormKey): void
{
$this->titleFormKey = $titleFormKey;
}

/**
* Sets the label to use for title field in forms, defaults to `Title`.
*/
protected function setTitleFormLabel(string $titleFormLabel): void
{
$this->titleFormLabel = $titleFormLabel;
}

/**
* Usually not required, but in case customization is needed you can use this method to set the name of the model
* this controller acts on.
Expand Down Expand Up @@ -789,6 +827,7 @@ protected function getIndexTableColumns(): TableColumns
$columns->add(
Text::make()
->field($this->titleColumnKey)
->title($this->titleColumnKey === 'title' && $this->titleColumnLabel === 'Title' ? twillTrans('twill::lang.main.title') : $this->titleColumnLabel)
->sortable()
->linkToEdit()
);
Expand Down Expand Up @@ -1731,6 +1770,7 @@ protected function getIndexData(array $prependScope = []): array
'permalink' => $this->getIndexOption('permalink'),
'bulkEdit' => $this->getIndexOption('bulkEdit'),
'titleFormKey' => $this->titleFormKey ?? $this->titleColumnKey,
'titleFormLabel' => $this->titleFormLabel ?? $this->titleColumnLabel,
'baseUrl' => $baseUrl,
'permalinkPrefix' => $this->getPermalinkPrefix($baseUrl),
'additionalTableActions' => $this->additionalTableActions(),
Expand Down Expand Up @@ -2211,6 +2251,7 @@ protected function form(?int $id, ?TwillModelContract $item = null): array
'moduleName' => $this->moduleName,
'routePrefix' => $this->routePrefix,
'titleFormKey' => $this->titleFormKey ?? $this->titleColumnKey,
'titleFormLabel' => $this->titleFormLabel ?? $this->titleColumnLabel,
'publish' => $item->canPublish ?? true,
'publishDate24Hr' => Config::get('twill.publish_date_24h') ?? false,
'publishDateFormat' => Config::get('twill.publish_date_format') ?? null,
Expand Down
3 changes: 2 additions & 1 deletion views/partials/create.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@php
$titleFormKey = $titleFormKey ?? 'title';
$titleFormLabel = $titleFormLabel ?? 'Title';
@endphp
<x-twill::input
:name="$titleFormKey"
:label="$titleFormKey === 'title' ? twillTrans('twill::lang.modal.title-field') : ucfirst($titleFormKey)"
:label="$titleFormKey === 'title' && $titleFormLabel === 'Title' ? twillTrans('twill::lang.modal.title-field') : $titleFormLabel"
:translated="$translateTitle ?? false"
:required="true"
on-change="formatPermalink"
Expand Down