You are here

public function ElevateZoomPlusForm::typecastOptionset in ElevateZoom Plus 8

Same name and namespace in other branches
  1. 7 modules/ui/src/Form/ElevateZoomPlusForm.php \Drupal\elevatezoomplus_ui\Form\ElevateZoomPlusForm::typecastOptionset()

Returns the typecast values.

Parameters

array $settings: An array of Optionset settings.

1 call to ElevateZoomPlusForm::typecastOptionset()
ElevateZoomPlusForm::submitForm in modules/ui/src/Form/ElevateZoomPlusForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…

File

modules/ui/src/Form/ElevateZoomPlusForm.php, line 642

Class

ElevateZoomPlusForm
Extends base form for elevatezoomplus instance configuration form.

Namespace

Drupal\elevatezoomplus_ui\Form

Code

public function typecastOptionset(array &$settings = []) {
  if (empty($settings)) {
    return;
  }
  $defaults = ElevateZoomPlus::defaultSettings();
  foreach ($defaults as $name => $value) {
    if (isset($settings[$name])) {

      // Seems double is ignored, and causes a missing schema, unlike float.
      $type = gettype($defaults[$name]);
      $type = $type == 'double' ? 'float' : $type;

      // Change float to integer if value is no longer float.
      if ($name == 'lensOpacity' || $name == 'tintOpacity') {
        $type = $settings[$name] == '0' || $settings[$name] == '1' ? 'integer' : 'float';
      }
      settype($settings[$name], $type);
    }
  }
  if (isset($settings['respond'])) {
    foreach ($settings['respond'] as &$respond) {
      if (isset($respond['enabled'])) {
        settype($respond['enabled'], 'boolean');
      }
      foreach ($defaults as $name => $value) {
        if (isset($respond[$name])) {
          $type = gettype($defaults[$name]);
          $type = $type == 'double' ? 'float' : $type;

          // Change float to integer if value is no longer float.
          if ($name == 'lensOpacity' || $name == 'tintOpacity') {
            $type = $respond[$name] == '0' || $respond[$name] == '1' ? 'integer' : 'float';
          }
          settype($respond[$name], $type);
        }
      }
    }
  }
}