You are here

protected function SimplesitemapVariantsForm::stringToVariants in Simple XML sitemap 8.3

Parameters

$variant_string:

Return value

array

2 calls to SimplesitemapVariantsForm::stringToVariants()
SimplesitemapVariantsForm::submitForm in src/Form/SimplesitemapVariantsForm.php
Form submission handler.
SimplesitemapVariantsForm::validateForm in src/Form/SimplesitemapVariantsForm.php
@todo Show multiple errors at once. @todo Allow numeric variant names, but bear in mind that they are stored as integer array keys due to how php arrays work.

File

src/Form/SimplesitemapVariantsForm.php, line 115

Class

SimplesitemapVariantsForm
Class SimplesitemapVariantsForm @package Drupal\simple_sitemap\Form

Namespace

Drupal\simple_sitemap\Form

Code

protected function stringToVariants($variant_string) {

  // Unify newline characters and explode into array.
  $variants_string_lines = explode("\n", str_replace("\r\n", "\n", $variant_string));

  // Remove empty values and whitespaces from array.
  $variants_string_lines = array_filter(array_map('trim', $variants_string_lines));
  $variants = [];
  foreach ($variants_string_lines as $i => &$line) {
    $variant_settings = explode('|', $line);
    $name = strtolower(trim($variant_settings[0]));
    $variants[$name]['type'] = !empty($variant_settings[1]) ? trim($variant_settings[1]) : SimplesitemapManager::DEFAULT_SITEMAP_TYPE;
    $variants[$name]['label'] = !empty($variant_settings[2]) ? trim($variant_settings[2]) : $name;
  }
  return $variants;
}