public static function flattenData(array $data, $prefix = NULL, $label = array()) {
    $flattened_data = array();
    if (isset($data['#label'])) {
      $label[] = $data['#label'];
    }
    // Each element is either a text (has #text property defined) or has children,
    // not both.
    if (!empty($data['#text'])) {
      $flattened_data[$prefix] = $data;
      $flattened_data[$prefix]['#parent_label'] = $label;
    }
    else {
      $prefix = isset($prefix) ? $prefix . self::ARRAY_DELIMITER : '';
      foreach (self::elementChildren($data) as $key) {
        $flattened_data += self::flattenData($data[$key], $prefix . $key, $label);
      }
    }
    return $flattened_data;
  }