Drupal 8 Can't persist custom template content type form

独自空忆成欢 提交于 2020-02-05 03:42:05

问题


I am trying to display and customize an add form page.

My content type, created via admin interface, is simple but uses workbench moderation module to manage content entity state (draft, published and archived).

I use this code to display form :

my__module.routing.yml

my__module.declare_security_practice:
  path: '/declarer-une-pratique-securite'
  defaults:
    _controller: '\Drupal\node\Controller\NodeController::add'
    _title: 'Déclarer une pratique sécurité'
    node_type: 'pratiques_securite'
  requirements:
    _node_add_access: 'node:pratiques_securite'

my__module.module

function my__module_form_node_pratiques_securite_form_alter(&$form, FormStateInterface &$form_state) {
   $form['#theme'] = ['pratiques_securite_form'];
}

function my__module_theme() {
  return array(
    'pratiques_securite_form' => array(
        'render element' => 'form',
        'template' => 'pratiques-security-form'
    ),
  );
}

pratiques-securite-form.html.twig

{{ form }}

I can display and customize my form successfully, but when i valid my form using "Pusblished, "Save as draft" or other button in the form, I am redirected to preview page and my content is not persisted on database.

On my form, if I change form action from "/declarer-une-pratique-securite" to "/node/add/pratiques_securite" (admin path), all is ok, content is saved successfully.

Could you tell me what to add in my code for my content to be persisted in a database ?

Thank you in advance

来源:https://stackoverflow.com/questions/38962963/drupal-8-cant-persist-custom-template-content-type-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!