2017-01-17 38 views

回答

0

「類型」是節點的機器名

「標題」是你想給新節點

您可以添加在您的節點使用更多的「FIELD_NAMES」稱號

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

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

    $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); 

    } 

有關如何設置自定義窗體的更多信息: https://www.drupal.org/docs/8/api/form-api/introduction-to-form-api

相關問題