"Drupal8表单提交后跳转页面"
Published on Aug. 22, 2023, 12:07 p.m.
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);
}