How to get arguments form url ?
Use entity (node, user ...) as parameters in route.
Exemple 1 : Form with Node
in routing.yml
my.node.info:
path: '/user/contactmail/{node}'
defaults:
_form: '\Drupal\myx_meet\Form\ContactUserForm'
_title: 'Contact'
requirements:
_permission: 'access content'
options:
parameters:
node:
type: entity:node
In ContactUserForm
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
// OR AccountInterface for $user
dpm($node);
//............... Your form
}
To use a 'String' as parameters:
parameters:
parametername:
type: String
Another Example with Options, Defalt values ...
mymodule.content.view:
path: '/content/{type}/{node}/{id}/{title}/{offset}'
defaults:
_controller: '\Drupal\mymodule\Controller\ContentViewer::view'
_title: 'View'
offset: '0'
title: 'untitled'
requirements:
_access: 'TRUE'
options:
parameters:
node:
type: entity:node
title:
type: String
id:
type: Integer
More details : https://www.drupal.org/node/2310425
Comments1
Thank you!
I've searched high and low for an example of a non-entity parameter type. Thanks so much for this example. I was trying int, but didn't try Integer.