trait OptionsEnumTrait
Helper functions to translate enum cases into an array of options.
Hierarchy
- trait \Drupal\Core\Utility\OptionsEnumTrait
2 files declare their use of OptionsEnumTrait
- CommentPreviewMode.php in core/
modules/ comment/ src/ CommentPreviewMode.php - NodePreviewMode.php in core/
modules/ node/ src/ NodePreviewMode.php
File
-
core/
lib/ Drupal/ Core/ Utility/ OptionsEnumTrait.php, line 10
Namespace
Drupal\Core\UtilityView source
trait OptionsEnumTrait {
/**
* Gets the label for this enum case.
*/
abstract public function label() : string|\Stringable;
/**
* Returns an array of options for use in form API.
*
* @return array<int|string, string|\Stringable>
* A mapping of values to their corresponding labels.
*/
public static function asOptions() : array {
$options = [];
foreach (self::cases() as $case) {
$options[$case->value] = $case->label();
}
return $options;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
OptionsEnumTrait::asOptions | public static | function | Returns an array of options for use in form API. |
OptionsEnumTrait::label | abstract public | function | Gets the label for this enum case. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.