Skip to content

Instantly share code, notes, and snippets.

@peterlozano
Created June 23, 2016 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterlozano/fa828ba21a6c770c462204ce5879c657 to your computer and use it in GitHub Desktop.
Save peterlozano/fa828ba21a6c770c462204ce5879c657 to your computer and use it in GitHub Desktop.
Tab in node page
# 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'
<?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