2

In Drupal 7 they can be found in object that is returned by field_info_instance(). Is there a way to get widget settings for certain field name and bundle in Drupal 8?

2

I found the way :-)

$settings = entity_get_form_display('node', 'article', 'default')
  ->getComponent('field_image')['settings'];
1

Widget settings are part of entity form displays, not field settings

  • 1
    Correct, but could use some more information/example code :) – Berdir Nov 16 '14 at 19:29
1

I believe the new way, as entity_get_form_display is being deprecated, is this:

$entity_type = 'node';
$bundle = 'page';
$form_mode = 'default';

$form_display = \Drupal::entityTypeManager()
  ->getStorage('entity_form_display')
  ->load($entity_type . '.' . $bundle . '.' . $form_mode);

$specific_widget_type = $form_display->getComponent('some_specific_field_machine_name');
if($specific_widget_type['type'] == 'some_widget_machine_name';

// ^ OR v

$widget_types = $form_display->getComponents();
foreach ($widget_types as $widget_type) {
  if ($widget_type['type'] == "some_widget_machine_name") {
    // Do something
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.