You are here

protected function FullCalendar::castNestedValues in FullCalendar 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::castNestedValues()

Casts form values to a given type, if defined.

Parameters

array $values: An array of fullcalendar option values.

array $form: The fullcalendar option form definition.

string|null $current_key: (optional) The current key being processed. Defaults to NULL.

array $parents: (optional) An array of parent keys when recursing through the nested array. Defaults to an empty array.

1 call to FullCalendar::castNestedValues()
FullCalendar::validateOptionsForm in src/Plugin/views/style/FullCalendar.php
Validate the options form.

File

src/Plugin/views/style/FullCalendar.php, line 190

Class

FullCalendar
Plugin annotation @ViewsStyle( id = "fullcalendar", title = @Translation("FullCalendar"), help = @Translation("Displays items on a calendar."), theme = "fullcalendar", theme_file = "fullcalendar.theme.inc", display_types = {"normal"} )

Namespace

Drupal\fullcalendar\Plugin\views\style

Code

protected function castNestedValues(array &$values, array $form, $current_key = NULL, array $parents = []) {
  foreach ($values as $key => &$value) {

    // We are leaving a recursive loop, remove the last parent key.
    if (empty($current_key)) {
      array_pop($parents);
    }

    // In case we recurse into an array, or need to specify the key for
    // drupal_array_get_nested_value(), add the current key to $parents.
    $parents[] = $key;
    if (is_array($value)) {

      // Enter another recursive loop.
      $this
        ->castNestedValues($value, $form, $key, $parents);
    }
    else {

      // Get the form definition for this key.
      $form_value = NestedArray::getValue($form, $parents);

      // Check to see if #data_type is specified, if so, cast the value.
      if (isset($form_value['#data_type'])) {
        settype($value, $form_value['#data_type']);
      }

      // Remove the current key from $parents to move on to the next key.
      array_pop($parents);
    }
  }
}