menu

Drupal8表单提交后跳转页面

use Drupal\node\Entity\Node;
use Drupal\Core\Url;

public function submitForm(array &$form, FormStateInterface $form_state) {

//save Company as node
$newCompanyNode = Node::create([
'type' => 'company',
'title' => $form_state->getValue('company'),
//'field_name' => $value,
]);

$newCompanyNode->save();
drupal_set_message('Your company has been registered.', 'status');
//需要跳转的页面
$url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' => $newCompanyNode->id()]);
return $form_state->setRedirectUrl($url);

}
编辑