You are here

protected function EntityReferenceAutocompleteWidget::getAutocreateBundle in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget::getAutocreateBundle()

Returns the name of the bundle which will be used for autocreated entities.

Return value

string The bundle name.

1 call to EntityReferenceAutocompleteWidget::getAutocreateBundle()
EntityReferenceAutocompleteWidget::formElement in core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
Returns the form for a single field widget.

File

core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php, line 148
Contains \Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget.

Class

EntityReferenceAutocompleteWidget
Plugin implementation of the 'entity_reference_autocomplete' widget.

Namespace

Drupal\Core\Field\Plugin\Field\FieldWidget

Code

protected function getAutocreateBundle() {
  $bundle = NULL;
  if ($this
    ->getSelectionHandlerSetting('auto_create')) {

    // If the 'target_bundles' setting is restricted to a single choice, we
    // can use that.
    if (($target_bundles = $this
      ->getSelectionHandlerSetting('target_bundles')) && count($target_bundles) == 1) {
      $bundle = reset($target_bundles);
    }
    else {

      // @todo Expose a proper UI for choosing the bundle for autocreated
      // entities in https://www.drupal.org/node/2412569.
      $bundles = entity_get_bundles($this
        ->getFieldSetting('target_type'));
      $bundle = key($bundles);
    }
  }
  return $bundle;
}