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 configurable page headings using tokens #5566

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/resources/lang/en/crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
'save_action_save_and_preview' => 'Save and preview',
'save_action_changed_notification' => 'Default behaviour after saving has been changed.',

// headings
'page_heading' => ':plural',
'page_subheading' => ':action :singular',

// Create form
'add' => 'Add',
'back_to_all' => 'Back to all ',
Expand Down
16 changes: 5 additions & 11 deletions src/resources/views/crud/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@

@section('header')
<section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
<h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}.</p>
@if ($crud->hasAccess('list'))
<p class="mb-0 ms-2 ml-2" bp-section="page-subheading-back-button">
<small>
<a href="{{ url($crud->route) }}" class="d-print-none font-sm">
<span><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></span>
</a>
</small>
</p>
@endif
@include('crud::inc.page_headings', [
'singular' => $crud->entity_name,
'plural' => $crud->entity_name_plural,
'action' => trans('backpack::crud.add')
])
</section>
@endsection

Expand Down
12 changes: 5 additions & 7 deletions src/resources/views/crud/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@

@section('header')
<section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
<h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}.</p>
@if ($crud->hasAccess('list'))
<p class="mb-0 ms-2 ml-2" bp-section="page-subheading-back-button">
<small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
</p>
@endif
@include('crud::inc.page_headings', [
'singular' => $crud->entity_name,
'plural' => $crud->entity_name_plural,
'action' => trans('backpack::crud.edit')
])
</section>
@endsection

Expand Down
29 changes: 29 additions & 0 deletions src/resources/views/crud/inc/page_headings.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h1
class="text-capitalize mb-0"
bp-section="page-heading">
{!! $crud->getHeading() ?? trans('backpack::crud.page_heading', [
'singular' => $singular,
'plural' => $plural,
'action' => $action
])
!!}
</h1>
<p
class="ms-2 ml-2 mb-0"
bp-section="page-subheading">
{!! $crud->getSubheading() ?? trans('backpack::crud.page_subheading', [
'singular' => $singular,
'plural' => $plural,
'action' => $action
])
!!}
</p>
@if ($backButton ?? true && $crud->hasAccess('list'))
<p class="mb-0 ms-2 ml-2" bp-section="page-subheading-back-button">
<small>
<a href="{{ url($crud->route) }}" class="d-print-none font-sm">
<span><i class="la la-angle-double-{{ config('backpack.base.html_direction') == 'rtl' ? 'right' : 'left' }}"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></span>
</a>
</small>
</p>
@endif
8 changes: 6 additions & 2 deletions src/resources/views/crud/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

@section('header')
<section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
<h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
<p class="ms-2 ml-2 mb-0" id="datatable_info_stack" bp-section="page-subheading">{!! $crud->getSubheading() ?? '' !!}</p>
@include('crud::inc.page_headings', [
'singular' => '',
'plural' => $crud->entity_name_plural,
'action' => '',
'backButton' => false
Comment on lines +17 to +20
Copy link
Member

@tabacitu tabacitu Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the empty strings here intentional?

Copy link
Contributor Author

@pxpm pxpm Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only reason why this PR is not merged yet I think I wouldn't have called for your judgment if it wasn't for this use case.

This triggers my "spidey" sense too, so it's super you have noticed the same. (I would have talked you about this anyway).

So the reason this happens is because in ListOperation we don't show any "action" (Create, Update, Preview etc..), and also we don't want to show any "singular", mean Monster.

Translating this to placeholders means we would show the Monsters (:plural) in the heading, and two empty strings in the sub heading (where usually we have Create Monster (:action : singular))

Ideally singular, plural, action placeholders should always have value, filled from crud variables, without caring in what operation they are used. To achieve this, we need to remove the heading and subheading from lang files, and make them part of each operation.
So that ListOperation can set heading to :plural and nothing in subheading, while CreateOperation set heading to :plural and subheading to :action :singular.

We can still keep the defaults for backwards compatibility, and set the operation.heading to null or something and we keep the same translations/behavior we currently have. But developer can setup operation.heading in their Controller and it would overwrite our defaults. I think this is way more resilient that this placeholder approach.

What you think ?

Copy link

@siberfx siberfx Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@section('header')
    <div class="container-fluid">

    <section class="header-operation container-fluid animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
        @include('crud::inc.page_headings', [
        'singular' => '',
        'plural' => $crud->entity_name_plural,
        'action' => '',
        'backButton' => false
        ])
    </section>
    </div>
@endsection

you forgot to add parent div, its broken when I tried :) and the same for reorder, show, create edit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @siberfx thanks for the heads up.

What div are you referring to ? From the code changes I didn't remove any div, I just moved the <h1> and the <p> to a new file.

Also I cannot find the mentioned div in the main branch of CRUD:

Maybe that's a custom change you made to your views ?

Cheers

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I saw between your @section codes, maybe I am the one who uses the outdated versions of these blades.. but if in updated version also contains the same structure, than I might be right :) just I applied these changes on my existing environment on local and saw them broken. so I decided to let you know :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @siberfx appreciated 🙏

Thing is that if you have those files overwritten in your local resources/views folder, you won't get the updated versions when/if we release them, so we can't break your app. 👍

This is still kind of POC, because I am still not happy with all the mumbo-jumbo setting "empty" stuff etc in some operations. I may have time to gives this a "fresh" look in the next month or so I hope 🙏

Cheers

])
</section>
@endsection

Expand Down
12 changes: 5 additions & 7 deletions src/resources/views/crud/reorder.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@

@section('header')
<section class="header-operation container-fluid animated fadeIn d-flex align-items-baseline d-print-none" bp-section="page-header">
<h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? trans('backpack::crud.reorder').' '.$crud->entity_name_plural !!}</p>
@if ($crud->hasAccess('list'))
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading-back-button">
<small><a href="{{ url($crud->route) }}" class="d-print-none font-sm"><i class="la la-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
</p>
@endif
@include('crud::inc.page_headings', [
'singular' => $crud->entity_name,
'plural' => $crud->entity_name_plural,
'action' => trans('backpack::crud.reorder')
])
</section>
@endsection

Expand Down
12 changes: 5 additions & 7 deletions src/resources/views/crud/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
@section('header')
<div class="container-fluid d-flex justify-content-between my-3">
<section class="header-operation animated fadeIn d-flex mb-2 align-items-baseline d-print-none" bp-section="page-header">
<h1 class="text-capitalize mb-0" bp-section="page-heading">{!! $crud->getHeading() ?? $crud->entity_name_plural !!}</h1>
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading">{!! $crud->getSubheading() ?? mb_ucfirst(trans('backpack::crud.preview')).' '.$crud->entity_name !!}</p>
@if ($crud->hasAccess('list'))
<p class="ms-2 ml-2 mb-0" bp-section="page-subheading-back-button">
<small><a href="{{ url($crud->route) }}" class="font-sm"><i class="la la-angle-double-left"></i> {{ trans('backpack::crud.back_to_all') }} <span>{{ $crud->entity_name_plural }}</span></a></small>
</p>
@endif
@include('crud::inc.page_headings', [
'singular' => $crud->entity_name,
'plural' => $crud->entity_name_plural,
'action' => trans('backpack::crud.preview')
])
</section>
<a href="javascript: window.print();" class="btn float-end float-right"><i class="la la-print"></i></a>
</div>
Expand Down