Created
June 23, 2016 14:11
-
-
Save peterlozano/fa828ba21a6c770c462204ce5879c657 to your computer and use it in GitHub Desktop.
Tab in node page
This file contains 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 characters
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 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 characters
# 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 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 characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment