<?php

namespace Drupal\restaurant_menus\Form;

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

class Addmenu extends AppForm {

   /*
   * @return string
   *   The unique string identifying the form.
   */
  public function getFormId()
  {
    return 'menu_add_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state)
  {
    $form['title'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Title'),
      '#description' => $this->t('Enter a title for the menu.'),
      '#required' => TRUE,
    ];

    $form['body'] = array(
      '#type' => 'textarea',
      '#title' => 'Description',
      );

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

    return $form;
  }

  public function submitForm(array &$form, FormStateInterface $form_state)
  {

  }

  public function validateForm(array &$form, FormStateInterface $form_state)
  {
    $date = date("Y-m-d H:i:s");
    $insert = array(
      'name' => $form_state->getValue('title'),
      'active' => 0,
      'description' => $form_state->getValue('body'),
      'created' => $date,
      'modified' => $date
    );
    $this->conn->insert('restaurant_menus')->fields($insert)->execute();
    $this->addMessage('Added menu ' . $form_state->getValue('title'))->http_redirect('/admin/restaurant/menus');
  }




}
