function BlockContentTypeForm::save

Same name in other branches
  1. 9 core/modules/block_content/src/BlockContentTypeForm.php \Drupal\block_content\BlockContentTypeForm::save()
  2. 8.9.x core/modules/block_content/src/BlockContentTypeForm.php \Drupal\block_content\BlockContentTypeForm::save()
  3. 10 core/modules/block_content/src/BlockContentTypeForm.php \Drupal\block_content\BlockContentTypeForm::save()

Overrides EntityForm::save

File

core/modules/block_content/src/BlockContentTypeForm.php, line 109

Class

BlockContentTypeForm
The block content type entity form.

Namespace

Drupal\block_content

Code

public function save(array $form, FormStateInterface $form_state) {
    $block_type = $this->entity;
    $status = $block_type->save();
    $edit_link = $this->entity
        ->toLink($this->t('Edit'), 'edit-form')
        ->toString();
    $logger = $this->logger('block_content');
    if ($status == SAVED_UPDATED) {
        $this->messenger()
            ->addStatus($this->t('Block type %label has been updated.', [
            '%label' => $block_type->label(),
        ]));
        $logger->notice('Block type %label has been updated.', [
            '%label' => $block_type->label(),
            'link' => $edit_link,
        ]);
    }
    else {
        block_content_add_body_field($block_type->id());
        $this->messenger()
            ->addStatus($this->t('Block type %label has been added.', [
            '%label' => $block_type->label(),
        ]));
        $logger->notice('Block type %label has been added.', [
            '%label' => $block_type->label(),
            'link' => $edit_link,
        ]);
    }
    $form_state->setRedirectUrl($this->entity
        ->toUrl('collection'));
}

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