protected function ChooseComponentController::getSortedAllowedTypes in Layout Paragraphs 2.0.x
Returns an array of sorted allowed component / paragraph types.
Parameters
array $settings: The handler settings.
Return value
array An array of sorted, allowed paragraph bundles.
1 call to ChooseComponentController::getSortedAllowedTypes()
- ChooseComponentController::getComponentTypes in src/
Controller/ ChooseComponentController.php - Returns an array of available component types.
File
- src/
Controller/ ChooseComponentController.php, line 212
Class
- ChooseComponentController
- ChooseComponentController controller class.
Namespace
Drupal\layout_paragraphs\ControllerCode
protected function getSortedAllowedTypes(array $settings) {
$bundles = $this->entityTypeBundleInfo
->getBundleInfo('paragraph');
if (!empty($settings['target_bundles'])) {
if (isset($settings['negate']) && $settings['negate'] == '1') {
$bundles = array_diff_key($bundles, $settings['target_bundles']);
}
else {
$bundles = array_intersect_key($bundles, $settings['target_bundles']);
}
}
// Support for the paragraphs reference type.
if (!empty($settings['target_bundles_drag_drop'])) {
$drag_drop_settings = $settings['target_bundles_drag_drop'];
$max_weight = count($bundles);
foreach ($drag_drop_settings as $bundle_info) {
if (isset($bundle_info['weight']) && $bundle_info['weight'] && $bundle_info['weight'] > $max_weight) {
$max_weight = $bundle_info['weight'];
}
}
// Default weight for new items.
$weight = $max_weight + 1;
foreach ($bundles as $machine_name => $bundle) {
$return_bundles[$machine_name] = [
'label' => $bundle['label'],
'weight' => isset($drag_drop_settings[$machine_name]['weight']) ? $drag_drop_settings[$machine_name]['weight'] : $weight,
];
$weight++;
}
}
else {
$weight = 0;
foreach ($bundles as $machine_name => $bundle) {
$return_bundles[$machine_name] = [
'label' => $bundle['label'],
'weight' => $weight,
];
$weight++;
}
}
uasort($return_bundles, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $return_bundles;
}