Skip to content

Add ListableOption enum and update Field class to use it#56

Merged
tdwesten merged 3 commits intotdwesten:mainfrom
kgirzadas:fix/fields-listable-option
Apr 17, 2025
Merged

Add ListableOption enum and update Field class to use it#56
tdwesten merged 3 commits intotdwesten:mainfrom
kgirzadas:fix/fields-listable-option

Conversation

@kgirzadas
Copy link
Contributor

@kgirzadas kgirzadas commented Apr 4, 2025

closes #55

@tdwesten Please review the following changes:

  • Introduced an ListableOption enum with three possible options: hidden, true, and false.
  • Updated the default value to hidden to align with Statamic’s default behavior.
  • Calling ->listable() method without arguments is equivalent to ListableOption::true.

Let me know if anything should be adjusted!

Copy link
Owner

@tdwesten tdwesten left a comment

Choose a reason for hiding this comment

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

Looking good, but please process my feedback! Thank you for extending this add-on!

case True = 'true';
case False = 'false';

public function toArray()
Copy link
Owner

Choose a reason for hiding this comment

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

You can skip this toArray function and use $option->value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I actually considered that, but in that case the returned value would be a string instead of a boolean. I’m not sure that would be entirely correct?

The same approach is used in other enums as well – for example, CollapseOption and BardInlineOption.

Also, if we change this, we’d need to update the tests too, e.g.:

expect($field->toArray()['field']['listable'])->toBe('true');

Please have another look and let me know what you think.

'instructions' => $this->instructions,
'instructions_position' => $this->instructionsPosition,
'listable' => $this->listable,
'listable' => $this->listable->toArray(),
Copy link
Owner

@tdwesten tdwesten Apr 4, 2025

Choose a reason for hiding this comment

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

So you can use here $this->listable->value :)

@kgirzadas kgirzadas requested a review from tdwesten April 4, 2025 14:00
@tdwesten
Copy link
Owner

Hi @kgirzadas,

I have made some small updates to your code. Thank you very much for your contribution.

@tdwesten tdwesten merged commit a665811 into tdwesten:main Apr 17, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field option listable always defaults to true

2 participants