protected function CustomLinksForm::stringToCustomLinks in Simple XML sitemap 4.x
Parameters
string $custom_links_string:
Return value
array
2 calls to CustomLinksForm::stringToCustomLinks()
- CustomLinksForm::submitForm in src/
Form/ CustomLinksForm.php - Form submission handler.
- CustomLinksForm::validateForm in src/
Form/ CustomLinksForm.php - Form validation handler.
File
- src/
Form/ CustomLinksForm.php, line 184
Class
- CustomLinksForm
- Class CustomLinksForm
Namespace
Drupal\simple_sitemap\FormCode
protected function stringToCustomLinks(string $custom_links_string) : array {
// Unify newline characters and explode into array.
$custom_links_string_lines = explode("\n", str_replace("\r\n", "\n", $custom_links_string));
// Remove empty values and whitespaces from array.
$custom_links_string_lines = array_filter(array_map('trim', $custom_links_string_lines));
$custom_links = [];
foreach ($custom_links_string_lines as $i => &$line) {
$link_settings = explode(' ', $line);
$custom_links[$i]['path'] = $link_settings[0];
// If two arguments are provided for a link, assume the first to be
// priority, the second to be changefreq.
if (!empty($link_settings[1]) && !empty($link_settings[2])) {
$custom_links[$i]['priority'] = $link_settings[1];
$custom_links[$i]['changefreq'] = $link_settings[2];
}
else {
// If one argument is provided for a link, guess if it is priority or
// changefreq.
if (!empty($link_settings[1])) {
if (is_numeric($link_settings[1])) {
$custom_links[$i]['priority'] = $link_settings[1];
}
else {
$custom_links[$i]['changefreq'] = $link_settings[1];
}
}
}
}
return $custom_links;
}