Skip to content

Instantly share code, notes, and snippets.

@peterlozano
Created June 23, 2016 14:11
Show Gist options
  • Select an option

  • Save peterlozano/fa828ba21a6c770c462204ce5879c657 to your computer and use it in GitHub Desktop.

Select an option

Save peterlozano/fa828ba21a6c770c462204ce5879c657 to your computer and use it in GitHub Desktop.

Revisions

  1. peterlozano created this gist Jun 23, 2016.
    5 changes: 5 additions & 0 deletions module_name.links.tasks.yml
    Original 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
    8 changes: 8 additions & 0 deletions module_name.routing.yml
    Original 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'
    55 changes: 55 additions & 0 deletions src_Form_MyPageForm.php
    Original 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);

    }
    }