You are here

protected function TourForm::routesFromArray in Tour UI 8

Rebuild the lines into route structures.

  • route_name
  • route_params
    • key:value

Parameters

string $routes_in:

Return value

array

2 calls to TourForm::routesFromArray()
TourForm::submitForm in src/Form/TourForm.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…
TourForm::validateForm in src/Form/TourForm.php
Form validation handler.

File

src/Form/TourForm.php, line 326

Class

TourForm
Form controller for the tour entity edit forms.

Namespace

Drupal\tour_ui\Form

Code

protected function routesFromArray($routes_in) {

  // Normalize the new lines
  $routes_in = preg_replace("/(\r\n?|\n)/", "\n", $routes_in);
  $routes_in = explode("\n", $routes_in);

  // trim each line
  $routes_in = array_map('trim', $routes_in);
  $routes = [];
  $route = null;
  foreach ($routes_in as $line) {
    if (empty($line)) {
      continue;
    }
    if (strpos($line, '-') !== 0) {
      $routes[] = [];
      $route =& $routes[count($routes) - 1];
      $route['route_name'] = $line;
    }
    else {
      if (count($routes) === 0) {

        // abort when having a route_params without a route_name
        break;
      }
      list($key, $value) = explode(':', $line, 2);
      $key = trim(substr($key, 1));
      $value = trim($value);
      $route['route_params'][$key] = $value;
    }
  }
  return $routes;
}