- Issue created by @b0gucki3
- 🇨🇭Switzerland berdir Switzerland
Our reference handler has two settings, to also control order as well as the inverted stuff. I recommend to change the settings through the UI and then diff the changes with config import/export.
- 🇮🇪Ireland b0gucki3 Limerick
That does not really answer my question, as I wanted to set the available paragraphs in a paragraph field using code only, not the UI.
That said, I figured out how to do it with code alone.
As @berdir mentioned, there are two handler settings (target_bundles and target_bundles_drag_drop). The target_bundles_drag_drop setting needs to be configured. Here's an example implementation, in case someone else needs it.
$field_definition = \Drupal::entityTypeManager()->getStorage('field_config') ->load('node.' . $content_type . '.' . $field_name); // Ensure the field exists and has the target_bundles setting. if ($field_definition) { // Get the handler settings, which contain 'target_bundles'. $handler_settings = $field_definition->getSetting('handler_settings'); // Define the allowed types with their configuration. $target_bundles = $handler_settings['target_bundles']; $target_bundles[$paragraph_type] = $paragraph_type; // Define the target_bundles_drag_drop structure. $target_bundles_drag_drop = $handler_settings['target_bundles_drag_drop']; $target_bundles_drag_drop[$paragraph_type] = [ 'enabled' => true, ]; // Define the handler settings. $handler_settings = [ 'target_bundles' => $target_bundles, 'negate' => 0, 'target_bundles_drag_drop' => $target_bundles_drag_drop, ]; // Update the field configuration. $field_definition->setSetting('handler_settings', $handler_settings); // Save the updated field configuration. $field_definition->save(); }
Automatically closed - issue fixed for 2 weeks with no activity.