public function VarbaseBootstrapParagraphsSettingsForm::optionsExtractAllowedListTextValues in Varbase Bootstrap Paragraphs 8.4
Same name and namespace in other branches
- 8.7 src/Form/VarbaseBootstrapParagraphsSettingsForm.php \Drupal\varbase_bootstrap_paragraphs\Form\VarbaseBootstrapParagraphsSettingsForm::optionsExtractAllowedListTextValues()
- 8.5 src/Form/VarbaseBootstrapParagraphsSettingsForm.php \Drupal\varbase_bootstrap_paragraphs\Form\VarbaseBootstrapParagraphsSettingsForm::optionsExtractAllowedListTextValues()
- 8.6 src/Form/VarbaseBootstrapParagraphsSettingsForm.php \Drupal\varbase_bootstrap_paragraphs\Form\VarbaseBootstrapParagraphsSettingsForm::optionsExtractAllowedListTextValues()
- 9.0.x src/Form/VarbaseBootstrapParagraphsSettingsForm.php \Drupal\varbase_bootstrap_paragraphs\Form\VarbaseBootstrapParagraphsSettingsForm::optionsExtractAllowedListTextValues()
Parses a string of 'allowed values' into an array.
Parameters
string $string: The list of allowed values in string format described in optionsExtractAllowedValues().
Return value
array/null The array of extracted key/value pairs, or NULL if the string is invalid.
See also
optionsExtractAllowedListTextValues()
2 calls to VarbaseBootstrapParagraphsSettingsForm::optionsExtractAllowedListTextValues()
- VarbaseBootstrapParagraphsSettingsForm::submitForm in src/
Form/ VarbaseBootstrapParagraphsSettingsForm.php - Submit Form.
- VarbaseBootstrapParagraphsSettingsForm::validateForm in src/
Form/ VarbaseBootstrapParagraphsSettingsForm.php - Validate Form.
File
- src/
Form/ VarbaseBootstrapParagraphsSettingsForm.php, line 128
Class
- VarbaseBootstrapParagraphsSettingsForm
- Provides form for managing module settings.
Namespace
Drupal\varbase_bootstrap_paragraphs\FormCode
public function optionsExtractAllowedListTextValues($string) {
$values = [];
$list = explode("\n", $string);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $position => $text) {
$value = $key = FALSE;
// Check for an explicit key.
$matches = [];
if (preg_match('/(.*)\\|(.*)/', $text, $matches)) {
// Trim key and value to avoid unwanted spaces issues.
$key = trim($matches[1]);
$value = trim($matches[2]);
$values[$key] = $value;
}
else {
return;
}
}
return $values;
}