protected function ReferenceWidget::getAutocreateBundle in Select (or other) 4.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/ReferenceWidget.php \Drupal\select_or_other\Plugin\Field\FieldWidget\ReferenceWidget::getAutocreateBundle()
Returns the name of the bundle which will be used for autocreated entities.
@todo This is shamelessly copied from EntityAutocomplete. We should probably file a core issue to turn this into a trait. The same goes for $this::getSelectionHandlerSetting()
@codeCoverageIgnore Ignore this function because it is a straight copy->paste.
Return value
string The bundle name.
1 call to ReferenceWidget::getAutocreateBundle()
- ReferenceWidget::formElement in src/
Plugin/ Field/ FieldWidget/ ReferenceWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ ReferenceWidget.php, line 211
Class
- ReferenceWidget
- Plugin implementation of the 'select_or_other_reference' widget.
Namespace
Drupal\select_or_other\Plugin\Field\FieldWidgetCode
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 = $this->bundleInfoService
->getBundleInfo($this
->getFieldSetting('target_type'));
$bundle = key($bundles);
}
}
return $bundle;
}