public function WebformElementManager::getSortedDefinitions in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElementManager.php \Drupal\webform\Plugin\WebformElementManager::getSortedDefinitions()
Gets sorted plugin definitions.
Parameters
array[]|null $definitions: (optional) The plugin definitions to sort. If omitted, all plugin definitions are used.
string $sort_by: The property to sort plugin definitions by. Only 'label' and 'category' are supported. Defaults to label.
Return value
array[] An array of plugin definitions, sorted by category and label.
Overrides CategorizingPluginManagerTrait::getSortedDefinitions
2 calls to WebformElementManager::getSortedDefinitions()
- WebformElementManager::getGroupedDefinitions in src/
Plugin/ WebformElementManager.php - Gets sorted plugin definitions grouped by category.
- WebformElementManager::getInstances in src/
Plugin/ WebformElementManager.php - Get all available webform element plugin instances.
File
- src/
Plugin/ WebformElementManager.php, line 276
Class
- WebformElementManager
- Provides a plugin manager for webform element plugins.
Namespace
Drupal\webform\PluginCode
public function getSortedDefinitions(array $definitions = NULL, $sort_by = 'label') {
$definitions = isset($definitions) ? $definitions : $this
->getDefinitions();
switch ($sort_by) {
case 'category':
uasort($definitions, function ($a, $b) use ($sort_by) {
return strnatcasecmp($a['category'] . '-' . $a[$sort_by], $b['category'] . '-' . $b[$sort_by]);
});
break;
default:
uasort($definitions, function ($a, $b) use ($sort_by) {
return strnatcasecmp($a[$sort_by], $b[$sort_by]);
});
break;
}
return $definitions;
}