<?php

namespace Drupal\restaurant_menus\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\restaurant\Form\AppForm;

class Addsection extends AppForm {

  /**
   * Returns a unique string identifying the form.
   *
   * The returned ID should be a unique string that can be a valid PHP function
   * name, since it's used in hook implementation names such as
   * hook_form_FORM_ID_alter().
   *
   * @return string
   *   The unique string identifying the form.
   */
  public function getFormId() {
    return 'menu_section_add';
  }

  public function buildForm(array $form, FormStateInterface $form_state)
  {

    $form['name'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Name'),
        '#description' => $this->t("Please enter a name for your menu section"),
        '#required' => true
    ];

    $form['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Add')
    ];

    return $form;
  }

  public function submitForm(array &$form, FormStateInterface $form_state)
  {
      $values = array(
        'name' => $form_state->getValue('name'),
        'created' => date("Y-m-d H:i:s"),
        'menu_id' => $this->getParam('menuid')
      );

      $this->conn->insert('restaurant_menu_sections')->fields($values)->execute();
      $this->addMessage('Added section ' . $form_state->getValue('name'))->http_redirect('/admin/restaurant/menu/' . $this->getParam('menuid'));
  }




}
