Skip to content

Commit

Permalink
Allow customizing term create label
Browse files Browse the repository at this point in the history
  • Loading branch information
daun committed Nov 10, 2024
1 parent 1d78ccf commit 7736e37
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
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

0 comments on commit 7736e37

Please sign in to comment.