Overrides \Drupal\Core\Entity\EntityFormController::save().
Overrides EntityFormController::save
public function save(array $form, array &$form_state) {
$block = $this->entity;
$insert = empty($block->id->value);
$block
->save();
$watchdog_args = array(
'@type' => $block
->bundle(),
'%info' => $block
->label(),
);
$block_type = entity_load('custom_block_type', $block->type->value);
$t_args = array(
'@type' => $block_type
->label(),
'%info' => $block
->label(),
);
if ($insert) {
watchdog('content', '@type: added %info.', $watchdog_args, WATCHDOG_NOTICE);
drupal_set_message(t('@type %info has been created.', $t_args));
}
else {
watchdog('content', '@type: updated %info.', $watchdog_args, WATCHDOG_NOTICE);
drupal_set_message(t('@type %info has been updated.', $t_args));
}
if ($block->id->value) {
$form_state['values']['id'] = $block->id->value;
$form_state['id'] = $block->id->value;
if ($insert) {
if ($theme = $block
->getTheme()) {
$form_state['redirect'] = 'admin/structure/block/add/custom_block:' . $block->uuid->value . '/' . $theme;
}
else {
$form_state['redirect'] = 'admin/structure/block/add/custom_block:' . $block->uuid->value . '/' . config('system.theme')
->get('default');
}
}
else {
$form_state['redirect'] = 'admin/structure/block';
}
}
else {
// In the unlikely case something went wrong on save, the block will be
// rebuilt and block form redisplayed.
drupal_set_message(t('The block could not be saved.'), 'error');
$form_state['rebuild'] = TRUE;
}
// Clear the page and block caches.
cache_invalidate_tags(array(
'content' => TRUE,
));
}