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

[5.x] Allow customizing term create label #11103

Merged
merged 2 commits into from
Nov 11, 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
3 changes: 2 additions & 1 deletion resources/js/components/terms/BaseCreateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
publish-container="base"
:initial-actions="actions"
method="post"
:initial-title="__('Create')"
:initial-title="taxonomyCreateLabel"
:taxonomy-handle="taxonomyHandle"
:breadcrumbs="breadcrumbs"
:initial-fieldset="fieldset"
Expand All @@ -31,6 +31,7 @@ export default {
props: [
'actions',
'taxonomyHandle',
'taxonomyCreateLabel',
'breadcrumbs',
'fieldset',
'values',
Expand Down
5 changes: 3 additions & 2 deletions resources/js/components/terms/CreateTermButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class="btn-primary flex items-center"
@click="create"
>
<span v-text="__('Create Term')" />
<span v-text="text" />
<svg-icon name="micro/chevron-down-xs" class="rtl:mr-2 ltr:ml-2 -mr-2 w-2" v-if="blueprints.length > 1" />
</button>
</template>
Expand All @@ -25,7 +25,8 @@ export default {

props: {
url: String,
blueprints: Array
blueprints: Array,
text: { type: String, default: () => __('Create Term') },
},

methods: {
Expand Down
1 change: 1 addition & 0 deletions resources/views/taxonomies/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@if($canCreate)
<create-term-button
url="{{ cp_route('taxonomies.terms.create', [$taxonomy->handle(), $site]) }}"
text="{{ $taxonomy->createLabel() }}"
:blueprints="{{ $blueprints->toJson() }}">
</create-term-button>
@endif
Expand Down
3 changes: 2 additions & 1 deletion resources/views/terms/create.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@extends('statamic::layout')
@section('title', $breadcrumbs->title('Create Term'))
@section('title', $breadcrumbs->title($taxonomyCreateLabel))
@section('wrapper_class', 'max-w-3xl')

@section('content')
<base-term-create-form
:actions="{{ json_encode($actions) }}"
taxonomy-handle="{{ $taxonomy }}"
taxonomy-create-label="{{ $taxonomyCreateLabel }}"
:breadcrumbs="{{ $breadcrumbs->toJson() }}"
:fieldset="{{ json_encode($blueprint) }}"
:values="{{ json_encode($values) }}"
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Controllers/CP/Taxonomies/TermsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ public function create(Request $request, $taxonomy, $site)
]);

$viewData = [
'title' => __('Create Term'),
'title' => $taxonomy->createLabel(),
'actions' => [
'save' => cp_route('taxonomies.terms.store', [$taxonomy->handle(), $site->handle()]),
],
'values' => $values,
'meta' => $fields->meta(),
'taxonomy' => $taxonomy->handle(),
'taxonomyCreateLabel' => $taxonomy->createLabel(),
'blueprint' => $blueprint->toPublishArray(),
'published' => $taxonomy->defaultPublishState(),
'locale' => $site->handle(),
Expand Down
13 changes: 13 additions & 0 deletions src/Taxonomies/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ public function layout($layout = null)
->args(func_get_args());
}

public function createLabel()
{
$key = "messages.{$this->handle()}_taxonomy_create_term";

$translation = __($key);

if ($translation === $key) {
return __('Create Term');
}

return $translation;
}

public function searchIndex($index = null)
{
return $this
Expand Down
7 changes: 7 additions & 0 deletions tests/Data/Taxonomies/TaxonomyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ public function it_gets_and_sets_the_term_template()
$this->assertEquals('foo', $taxonomy->termTemplate());
}

#[Test]
public function it_gets_and_sets_the_create_label()
{
$taxonomy = (new Taxonomy)->handle('tags');
$this->assertEquals('Create Term', $taxonomy->createLabel());
}

#[Test]
public function it_cannot_view_taxonomies_from_sites_that_the_user_is_not_authorized_to_see()
{
Expand Down
Loading