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

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Jul 17, 2024

WHY

BEFORE - What was wrong? What was happening before this PR?

The main idea behind this came up from #4902

We discussed it internally and aknowledge that the PR as is was not mergeable, and not everyone agreed with the change so it was postponed.

I was doing now a cleanup and stumbled upon it. I was one of the people that liked the "idea" of the PR. So I came up with this solution.

AFTER - What is happening after this PR?

This gives developers the flexibility to configure the page headers beyond just changing a word at a time.

Is this a good idea ? At first it looks 🤷

HOW

How did you achieve that, in technical terms?

Created two new language strings to represent the page_heading and page_subheading in full. By default accepted the needed parameters, but this can be extended in the future to pass additional parameters.

At the moment the available parameters are:
:singular - $crud->entity_name
:plural - $crud->entity_name_plural
:action - trans('crud.add/edit/preview'),

Is it a breaking change?

Maybe not ?

@pekka
Copy link
Contributor

pekka commented Jul 17, 2024

This sounds like a reasonable solution!

Comment on lines +17 to +20
'singular' => '',
'plural' => $crud->entity_name_plural,
'action' => '',
'backButton' => false
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 ?

@tabacitu
Copy link
Member

Very clean PR, well done @pxpm 👏👏👏

I have one thing that jumped out in a comment above. In addition to that:

  1. How will someone be able to change the heading/subheading? By changing swapping the :singular and :plural in the language file - which will change all the CRUDs in one go, correct?

  2. Only found one bug - on the ListOperation the subheading isn't where it's supposed to. In this operation, the subheading gets replaced with JS with the description that DataTables calculates.
    CleanShot 2024-07-24 at 17 07 34@2x

  3. For future reference, I do agree that in terms of visual hierarchy the BIGGEST heading should be "Create Article" not "Articles". Pedro convinced me of that on Discord. I just wish we had created something like this from the start (having the entity name as the "pre-heading" as Tabler defines it). But doing that right now... seems like it'd be a lot of work for very little benefit. And probably a breaking change. We have to take into account that:

  • people might have created custom operations, so if we push a pre-heading now those operations don't get it;
  • we'd have to style this in all 3 themes;

But if we want the "Create Article" as the default heading in the next version, adding a "pre-heading" is probably the way to go, if you ask me.

CleanShot 2024-07-24 at 17 12 10@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs Testing, Review or Docs
Development

Successfully merging this pull request may close these issues.

3 participants