You are here

protected function InsertComponentForm::newParagraph in Layout Paragraphs 2.0.x

Creates a new, empty paragraph empty of the provided type.

Parameters

\Drupal\paragraphs\ParagraphsTypeInterface $paragraph_type: The paragraph type.

Return value

\Drupal\paragraphs\ParagraphInterface The new paragraph.

1 call to InsertComponentForm::newParagraph()
InsertComponentForm::buildForm in src/Form/InsertComponentForm.php

File

src/Form/InsertComponentForm.php, line 220

Class

InsertComponentForm
Class InsertComponentForm.

Namespace

Drupal\layout_paragraphs\Form

Code

protected function newParagraph(ParagraphsTypeInterface $paragraph_type) {
  $entity_type = $this->entityTypeManager
    ->getDefinition('paragraph');
  $bundle_key = $entity_type
    ->getKey('bundle');

  /** @var \Drupal\paragraphs\ParagraphInterface $paragraph_entity */
  $paragraph = $this->entityTypeManager
    ->getStorage('paragraph')
    ->create([
    $bundle_key => $paragraph_type
      ->id(),
  ]);
  return $paragraph;
}