protected function InlineParagraphsWidget::getDefaultParagraphTypeMachineName

Returns the machine name for default paragraph type.

Return value

string Machine name for default paragraph type.

3 calls to InlineParagraphsWidget::getDefaultParagraphTypeMachineName()
InlineParagraphsWidget::formMultipleElements in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
InlineParagraphsWidget::getDefaultParagraphTypeLabelName in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Returns the default paragraph type.
InlineParagraphsWidget::settingsForm in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php

File

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1472

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

protected function getDefaultParagraphTypeMachineName() {
  $default_type = $this
    ->getSetting('default_paragraph_type');
  $allowed_types = $this
    ->getAllowedTypes();
  if ($default_type && isset($allowed_types[$default_type])) {
    return $default_type;
  }

  // Check if the user explicitly selected not to have any default Paragraph
  // type. Othewise, if there is only one type available, that one is the
  // default.
  if ($default_type === '_none') {
    return NULL;
  }
  if (count($allowed_types) === 1) {
    return key($allowed_types);
  }
  return NULL;
}