You are here

public static function DbtngExampleAddForm::create in Examples for Developers 8

Same name and namespace in other branches
  1. 3.x modules/dbtng_example/src/Form/DbtngExampleAddForm.php \Drupal\dbtng_example\Form\DbtngExampleAddForm::create()

We'll use the ContainerInjectionInterface pattern here to inject the current user and also get the string_translation service.

Overrides ContainerInjectionInterface::create

File

dbtng_example/src/Form/DbtngExampleAddForm.php, line 46

Class

DbtngExampleAddForm
Form to add a database entry, with all the interesting fields.

Namespace

Drupal\dbtng_example\Form

Code

public static function create(ContainerInterface $container) {
  $form = new static($container
    ->get('dbtng_example.repository'), $container
    ->get('current_user'));

  // The StringTranslationTrait trait manages the string translation service
  // for us. We can inject the service here.
  $form
    ->setStringTranslation($container
    ->get('string_translation'));
  $form
    ->setMessenger($container
    ->get('messenger'));
  return $form;
}