Chris@0: entity; Chris@0: Chris@0: $form = parent::form($form, $form_state); Chris@0: Chris@0: if ($this->operation == 'edit') { Chris@0: $form['#title'] = $this->t('Edit custom block %label', ['%label' => $block->label()]); Chris@0: } Chris@0: // Override the default CSS class name, since the user-defined custom block Chris@0: // type name in 'TYPE-block-form' potentially clashes with third-party class Chris@0: // names. Chris@0: $form['#attributes']['class'][0] = 'block-' . Html::getClass($block->bundle()) . '-form'; Chris@0: Chris@0: return $form; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function save(array $form, FormStateInterface $form_state) { Chris@0: $block = $this->entity; Chris@0: Chris@0: $insert = $block->isNew(); Chris@0: $block->save(); Chris@0: $context = ['@type' => $block->bundle(), '%info' => $block->label()]; Chris@0: $logger = $this->logger('block_content'); Chris@0: $block_type = $this->getBundleEntity(); Chris@0: $t_args = ['@type' => $block_type->label(), '%info' => $block->label()]; Chris@0: Chris@0: if ($insert) { Chris@0: $logger->notice('@type: added %info.', $context); Chris@17: $this->messenger()->addStatus($this->t('@type %info has been created.', $t_args)); Chris@0: } Chris@0: else { Chris@0: $logger->notice('@type: updated %info.', $context); Chris@17: $this->messenger()->addStatus($this->t('@type %info has been updated.', $t_args)); Chris@0: } Chris@0: Chris@0: if ($block->id()) { Chris@0: $form_state->setValue('id', $block->id()); Chris@0: $form_state->set('id', $block->id()); Chris@0: if ($insert) { Chris@0: if (!$theme = $block->getTheme()) { Chris@0: $theme = $this->config('system.theme')->get('default'); Chris@0: } Chris@0: $form_state->setRedirect( Chris@0: 'block.admin_add', Chris@0: [ Chris@0: 'plugin_id' => 'block_content:' . $block->uuid(), Chris@0: 'theme' => $theme, Chris@0: ] Chris@0: ); Chris@0: } Chris@0: else { Chris@18: $form_state->setRedirectUrl($block->toUrl('collection')); Chris@0: } Chris@0: } Chris@0: else { Chris@0: // In the unlikely case something went wrong on save, the block will be Chris@0: // rebuilt and block form redisplayed. Chris@17: $this->messenger()->addError($this->t('The block could not be saved.')); Chris@0: $form_state->setRebuild(); Chris@0: } Chris@0: } Chris@0: Chris@0: }