Drupal 8 Can't persist custom template content

2019-07-25 01:52发布

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

0条回答
登录 后发表回答