Skip to content

Instantly share code, notes, and snippets.

@adityaanurag
Created July 4, 2016 19:03
Show Gist options
  • Save adityaanurag/06b2c48c3a7a408400658279c758d4c3 to your computer and use it in GitHub Desktop.
Save adityaanurag/06b2c48c3a7a408400658279c758d4c3 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\manage_inventory\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Language\Language;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for the manage_inventory entity edit forms.
*
* @ingroup manage_inventory
*/
class InventoryForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\manage_inventory\Entity\Inventory */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$form['langcode'] = array(
'#title' => $this->t('Language'),
'#type' => 'language_select',
'#default_value' => $entity->getUntranslated()->language()->getId(),
'#languages' => Language::STATE_ALL,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirect('entity.content_entity_manage_inventory.collection');
$entity = $this->getEntity();
$entity->save();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment