function EntityReferenceAutocompleteWidget::getAutocreateBundle

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget::getAutocreateBundle()
  2. 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php \Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget::getAutocreateBundle()
  3. 10 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. If autocreate is not active, NULL will be returned.

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 167

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')) {
        $target_bundles = $this->getSelectionHandlerSetting('target_bundles');
        // If there's no target bundle at all, use the target_type. It's the
        // default for bundleless entity types.
        if (empty($target_bundles)) {
            $bundle = $this->getFieldSetting('target_type');
        }
        elseif (count($target_bundles) == 1) {
            $bundle = reset($target_bundles);
        }
        elseif (!($bundle = $this->getSelectionHandlerSetting('auto_create_bundle'))) {
            // If no bundle has been set as auto create target means that there is
            // an inconsistency in entity reference field settings.
            trigger_error(sprintf("The 'Create referenced entities if they don't already exist' option is enabled but a specific destination bundle is not set. You should re-visit and fix the settings of the '%s' (%s) field.", $this->fieldDefinition
                ->getLabel(), $this->fieldDefinition
                ->getName()), E_USER_WARNING);
        }
    }
    return $bundle;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.