Returns the sorted allowed types for a entity reference field.
array A list of arrays keyed by the paragraph type machine name with the following properties.
public function getAllowedTypes() {
$return_bundles = array();
/** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selection_manager */
$selection_manager = \Drupal::service('plugin.manager.entity_reference_selection');
$handler = $selection_manager
->getSelectionHandler($this->fieldDefinition);
if ($handler instanceof ParagraphSelection) {
$return_bundles = $handler
->getSortedAllowedTypes();
}
else {
$bundles = \Drupal::service('entity_type.bundle.info')
->getBundleInfo($this
->getFieldSetting('target_type'));
$weight = 0;
foreach ($bundles as $machine_name => $bundle) {
if (empty($this
->getSelectionHandlerSetting('target_bundles')) || in_array($machine_name, $this
->getSelectionHandlerSetting('target_bundles'))) {
$return_bundles[$machine_name] = array(
'label' => $bundle['label'],
'weight' => $weight,
);
$weight++;
}
}
}
return $return_bundles;
}