Version 1
[yaffs-website] / web / modules / contrib / inline_entity_form / tests / modules / inline_entity_form_test / src / IefTest.php
1 <?php
2
3 namespace Drupal\inline_entity_form_test;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Tests Inline entity form element.
10  */
11 class IefTest extends FormBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function getFormID() {
17     return 'ief_test';
18   }
19
20   /**
21    * {@inheritdoc}
22    */
23   public function buildForm(array $form, FormStateInterface $form_state, $form_mode = 'default') {
24     $form['inline_entity_form'] = [
25       '#type' => 'inline_entity_form',
26       '#entity_type' => 'node',
27       '#bundle' => 'ief_test_custom',
28       '#form_mode' => $form_mode,
29     ];
30     $form['submit'] = [
31       '#type' => 'submit',
32       '#value' => t('Save'),
33     ];
34     return $form;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function submitForm(array &$form, FormStateInterface $form_state) {
41     $entity = $form['inline_entity_form']['#entity'];
42     drupal_set_message(t('Created @entity_type @label.', ['@entity_type' => $entity->getEntityType()->getLabel(), '@label' => $entity->label()]));
43   }
44
45 }