public static function TermLevelItem::extractLevels in Term Level Field 8
Extracts levels (level-key => level-label) out of the field settings.
Level-label are not yet sanitized.
Return value
array Extracted levels.
3 calls to TermLevelItem::extractLevels()
- TermLevelFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ TermLevelFormatter.php - Builds a renderable array for a field value.
- TermLevelItem::validateLevels in src/
Plugin/ Field/ FieldType/ TermLevelItem.php - Validates levels value.
- TermLevelWidget::formElement in src/
Plugin/ Field/ FieldWidget/ TermLevelWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldType/ TermLevelItem.php, line 67
Class
- TermLevelItem
- Plugin for Term level field type.
Namespace
Drupal\term_level\Plugin\Field\FieldTypeCode
public static function extractLevels($value) {
$levels = [];
$list = explode("\n", $value);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $key => $value) {
if (strpos($value, '|') !== FALSE) {
list($level_key, $label) = explode('|', $value);
}
if (isset($level_key) && isset($level_key)) {
$levels[$level_key] = $label;
}
}
return $levels;
}