You are here

protected function AutocompleteDeluxeWidget::getAutocreateBundle in Autocomplete Deluxe 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php \Drupal\autocomplete_deluxe\Plugin\Field\FieldWidget\AutocompleteDeluxeWidget::getAutocreateBundle()

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

Return value

string The bundle name.

1 call to AutocompleteDeluxeWidget::getAutocreateBundle()
AutocompleteDeluxeWidget::formElement in src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php, line 315

Class

AutocompleteDeluxeWidget
Plugin implementation of the 'options_buttons' widget.

Namespace

Drupal\autocomplete_deluxe\Plugin\Field\FieldWidget

Code

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

    // If there's only one target bundle, use it.
    if (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;
}