Created
June 23, 2016 14:11
-
-
Save peterlozano/fa828ba21a6c770c462204ce5879c657 to your computer and use it in GitHub Desktop.
Revisions
-
peterlozano created this gist
Jun 23, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ module_name.my_page_form: route_name: module_name.my_page_form base_route: entity.node.canonical title: 'My Form Page' weight: 5 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # EXAMPLE WITH A FORM module_name.my_page_form: path: '/node/{node}/my-page-form' defaults: _form: '\Drupal\module_name\Form\MyPageForm' _title: 'My Form Page' requirements: _permission: 'administer my module' This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ <?php namespace Drupal\module_name\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\node\Entity\Node; /** * Class SettingsForm. * * @package Drupal\module_name\Form */ class MyPageForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { return 'module_name_node_my_page_form'; } /**v * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $request = \Drupal::request(); $nid = $request->attributes->get('node'); $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary', ); return $form; } /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $request = \Drupal::request(); $nid = $request->attributes->get('node'); $node = node_load($nid); } }