getBundleEntity example

/** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $block = $this->entity;

    $insert = $block->isNew();
    $block->save();
    $context = ['@type' => $block->bundle(), '%info' => $block->label()];
    $logger = $this->logger('block_content');
    $block_type = $this->getBundleEntity();
    $t_args = ['@type' => $block_type->label(), '%info' => $block->label()];

    if ($insert) {
      $logger->info('@type: added %info.', $context);
      $this->messenger()->addStatus($this->t('@type %info has been created.', $t_args));
    }
    else {
      $logger->info('@type: updated %info.', $context);
      $this->messenger()->addStatus($this->t('@type %info has been updated.', $t_args));
    }

    

  }

  /** * Should new revisions created on default. * * @return bool * New revision on default. */
  protected function getNewRevisionDefault() {
    $new_revision_default = FALSE;
    $bundle_entity = $this->getBundleEntity();
    if ($bundle_entity instanceof RevisionableEntityBundleInterface) {
      // Always use the default revision setting.       $new_revision_default = $bundle_entity->shouldCreateNewRevision();
    }
    return $new_revision_default;
  }

  /** * Checks whether the revision form fields should be added to the form. * * @return bool * TRUE if the form field should be added, FALSE otherwise. */
Home | Imprint | This part of the site doesn't use cookies.