You are here

public function CheckboxSettingType::settingsPreprocess in UI Patterns Settings 8

Preprocess setting variable.

Parameters

string $value: The stored value.

array $context: Context informations. Keys:

  • entity.

\Drupal\ui_patterns_settings\Definition\PatternDefinitionSetting $def: The pattern definition.

Return value

string The processed value.

Overrides PatternSettingTypeBase::settingsPreprocess

File

src/Plugin/UiPatterns/SettingType/CheckboxSettingType.php, line 21

Class

CheckboxSettingType
Checkbox setting type.

Namespace

Drupal\ui_patterns_settings\Plugin\UIPatterns\SettingType

Code

public function settingsPreprocess($value, array $context, PatternDefinitionSetting $def) {
  $selected_options = [];
  $defined_options = $def
    ->getOptions();
  if (is_array($value)) {
    foreach ($value as $checkbox_key => $checkbox_value) {
      if ($checkbox_value != "0") {
        $selected_options[$checkbox_key] = isset($defined_options[$checkbox_value]) ? $defined_options[$checkbox_value] : $checkbox_value;
      }
    }
  }
  return $selected_options;
}