/**
  * {@inheritdoc}
  */
 public static function settingsForm(FieldDefinitionInterface $field_definition)
 {
     $entity_manager = \Drupal::entityManager();
     $entity_type_id = $field_definition->getSetting('target_type');
     $selection_handler_settings = $field_definition->getSetting('handler_settings') ?: array();
     $entity_type = $entity_manager->getDefinition($entity_type_id);
     $bundles = $entity_manager->getBundleInfo($entity_type_id);
     // Merge-in default values.
     $selection_handler_settings += array('target_bundles' => array(), 'sort' => array('field' => '_none'), 'auto_create' => FALSE);
     if ($entity_type->hasKey('bundle')) {
         $bundle_options = array();
         foreach ($bundles as $bundle_name => $bundle_info) {
             $bundle_options[$bundle_name] = $bundle_info['label'];
         }
         $target_bundles_title = t('Bundles');
         // Default core entity types with sensible labels.
         if ($entity_type_id == 'node') {
             $target_bundles_title = t('Content types');
         } elseif ($entity_type_id == 'taxonomy_term') {
             $target_bundles_title = t('Vocabularies');
         }
         $form['target_bundles'] = array('#type' => 'checkboxes', '#title' => $target_bundles_title, '#options' => $bundle_options, '#default_value' => !empty($selection_handler_settings['target_bundles']) ? $selection_handler_settings['target_bundles'] : array(), '#required' => TRUE, '#size' => 6, '#multiple' => TRUE, '#element_validate' => array('_entity_reference_element_validate_filter'));
     } else {
         $form['target_bundles'] = array('#type' => 'value', '#value' => array());
     }
     if ($entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
         $fields = array();
         foreach (array_keys($bundles) as $bundle) {
             $bundle_fields = array_filter($entity_manager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) {
                 return !$field_definition->isComputed();
             });
             foreach ($bundle_fields as $field_name => $field_definition) {
                 /* @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
                 $columns = $field_definition->getFieldStorageDefinition()->getColumns();
                 // If there is more than one column, display them all, otherwise just
                 // display the field label.
                 // @todo: Use property labels instead of the column name.
                 if (count($columns) > 1) {
                     foreach ($columns as $column_name => $column_info) {
                         $fields[$field_name . '.' . $column_name] = t('@label (@column)', array('@label' => $field_definition->getLabel(), '@column' => $column_name));
                     }
                 } else {
                     $fields[$field_name] = t('@label', array('@label' => $field_definition->getLabel()));
                 }
             }
         }
         $form['sort']['field'] = array('#type' => 'select', '#title' => t('Sort by'), '#options' => array('_none' => t('- None -')) + $fields, '#ajax' => TRUE, '#limit_validation_errors' => array(), '#default_value' => $selection_handler_settings['sort']['field']);
         $form['sort']['settings'] = array('#type' => 'container', '#attributes' => array('class' => array('entity_reference-settings')), '#process' => array('_entity_reference_form_process_merge_parent'));
         if ($selection_handler_settings['sort']['field'] != '_none') {
             // Merge-in default values.
             $selection_handler_settings['sort'] += array('direction' => 'ASC');
             $form['sort']['settings']['direction'] = array('#type' => 'select', '#title' => t('Sort direction'), '#required' => TRUE, '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), '#default_value' => $selection_handler_settings['sort']['direction']);
         }
     }
     return $form;
 }