protected function LinkClassFieldWidget::getSelectOptions in Link class 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Field/FieldWidget/LinkClassFieldWidget.php \Drupal\link_class\Plugin\Field\FieldWidget\LinkClassFieldWidget::getSelectOptions()
Convert textarea lines into an array.
Parameters
string $string: The textarea lines to explode.
bool $summary: A flag to return a formatted list of classes available.
Return value
array An array keyed by the classes.
2 calls to LinkClassFieldWidget::getSelectOptions()
- LinkClassFieldWidget::formElement in src/
Plugin/ Field/ FieldWidget/ LinkClassFieldWidget.php - Returns the form for a single field widget.
- LinkClassFieldWidget::settingsSummary in src/
Plugin/ Field/ FieldWidget/ LinkClassFieldWidget.php - Returns a short summary for the current widget settings.
File
- src/
Plugin/ Field/ FieldWidget/ LinkClassFieldWidget.php, line 192
Class
- LinkClassFieldWidget
- Plugin implementation of the 'link_class_field_widget' widget.
Namespace
Drupal\link_class\Plugin\Field\FieldWidgetCode
protected function getSelectOptions($string, $summary = FALSE) {
$options = [];
$lines = preg_split("/\\r\\n|\\r|\\n/", trim($string));
$lines = array_filter($lines);
foreach ($lines as $line) {
list($class, $label) = explode('|', trim($line));
$label = $label ?: $class;
$options[$class] = $label;
}
if ($summary) {
return implode(', ', array_keys($options));
}
return $options;
}