Skip to main content

GravityKit\GravityMigrate\Schema\Choice

One option in a select, radio, checkbox or product field.

Six slots cover every platform: what the reader sees, what the entry records, whether it starts chosen, and the price, image and score the commerce and survey fields add.

The array form spells the visible slot two ways -- text and label -- and a reader that knows only one of them gets an empty string, so the option renders blank. Both are read here.

What a platform keeps on a choice that these slots have no room for is carried untouched: this is the only place a choice's data lives on the way through.

Since: %ver%

Source: src/Schema/Choice.php:24

Details

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Schema

Methods

MethodDescription
of()An option.
from_array()An option from the array shape adapters hand over.
to_array()The array shape adapters read.
get_text()What the reader sees.
set_text()Changes what the reader sees.
get_value()What the entry records.
set_value()Changes what the entry records.
is_selected()Whether it starts chosen.
set_selected()Sets whether it starts chosen.
get_price()What choosing it costs; null when it has no price.
get_image_url()The image shown for it; null when there is none.
get_score()What choosing it scores; null when it scores nothing.

Method Reference

of()

public static function of( string $text, ?string $value=null ): self

An option.

An option given no value of its own records its text, because a value of nothing records nothing: the entry keeps a blank where the answer belongs and every report of that form reads as though nobody answered. An empty string passed on purpose is how a placeholder option is written, so only an absent value is filled in.

Parameters

NameTypeDefaultDescription
$textstringWhat the reader sees.
$valuestring | nullnullWhat the entry records; null to record the text.

Returns

  • self

Since: %ver%

Source: src/Schema/Choice.php:138

from_array()

public static function from_array( array $choice ): self

An option from the array shape adapters hand over.

Parameters

NameTypeDefaultDescription
$choicearrayChoice array.

Returns

  • self

Since: %ver%

Source: src/Schema/Choice.php:151

to_array()

public function to_array(): array

The array shape adapters read.

Returns

  • array — The choice's own keys, with anything the platform wrote that these slots have no room for merged back in.

Since: %ver%

Source: src/Schema/Choice.php:186

get_text()

public function get_text(): string

What the reader sees.

Returns

  • string

Since: %ver%

Source: src/Schema/Choice.php:215

set_text()

public function set_text( string $text ): self

Changes what the reader sees.

Parameters

NameTypeDefaultDescription
$textstringOption text.

Returns

  • self

Since: %ver%

Source: src/Schema/Choice.php:228

get_value()

public function get_value(): string

What the entry records.

Returns

  • string

Since: %ver%

Source: src/Schema/Choice.php:241

set_value()

public function set_value( string $value ): self

Changes what the entry records.

Parameters

NameTypeDefaultDescription
$valuestringRecorded value.

Returns

  • self

Since: %ver%

Source: src/Schema/Choice.php:254

is_selected()

public function is_selected(): bool

Whether it starts chosen.

Returns

  • bool

Since: %ver%

Source: src/Schema/Choice.php:267

set_selected()

public function set_selected( bool $is_selected ): self

Sets whether it starts chosen.

Parameters

NameTypeDefaultDescription
$is_selectedboolWhether chosen by default.

Returns

  • self

Since: %ver%

Source: src/Schema/Choice.php:280

get_price()

public function get_price(): ?string

What choosing it costs; null when it has no price.

Returns

  • string | null

Since: %ver%

Source: src/Schema/Choice.php:293

get_image_url()

public function get_image_url(): ?string

The image shown for it; null when there is none.

Returns

  • string | null

Since: %ver%

Source: src/Schema/Choice.php:304

get_score()

public function get_score(): ?string

What choosing it scores; null when it scores nothing.

Returns

  • string | null

Since: %ver%

Source: src/Schema/Choice.php:315