Updated all the contrib modules to their latest versions.
[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 use Drupal\node\Entity\Node;
8
9 /**
10  * Tests Inline entity form element.
11  */
12 class IefTest extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormID() {
18     return 'ief_test';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildForm(array $form, FormStateInterface $form_state, $form_mode = 'default', Node $node = NULL) {
25     $form['inline_entity_form'] = [
26       '#type' => 'inline_entity_form',
27       '#entity_type' => 'node',
28       '#bundle' => 'ief_test_custom',
29       '#form_mode' => $form_mode,
30     ];
31     $form['submit'] = [
32       '#type' => 'submit',
33       '#value' => t('Save'),
34     ];
35     if (!empty($node)) {
36       $form['inline_entity_form']['#default_value'] = $node;
37       $form['submit']['#value'] = t('Update');
38     }
39
40     return $form;
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function submitForm(array &$form, FormStateInterface $form_state) {
47     $entity = $form['inline_entity_form']['#entity'];
48     drupal_set_message(t('Created @entity_type @label.', ['@entity_type' => $entity->getEntityType()->getLabel(), '@label' => $entity->label()]));
49   }
50
51 }