You are here

protected function InlineParagraphsWidget::getDefaultParagraphTypeMachineName in Paragraphs Sets 8

Returns the machine name for default paragraph set.

Return value

string Machine name for default paragraph set.

Overrides InlineParagraphsWidget::getDefaultParagraphTypeMachineName

2 calls to InlineParagraphsWidget::getDefaultParagraphTypeMachineName()
InlineParagraphsWidget::formMultipleElements in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Special handling to create form elements for multiple values.
InlineParagraphsWidget::getDefaultParagraphTypeLabelName in src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
Returns the default paragraph type.

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 440

Class

InlineParagraphsWidget
Plugin definition of the 'entity_reference paragraphs sets' widget.

Namespace

Drupal\paragraphs_sets\Plugin\Field\FieldWidget

Code

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

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