function CacheExampleForm::create
Same name in other branches
- 4.0.x modules/cache_example/src/Form/CacheExampleForm.php \Drupal\cache_example\Form\CacheExampleForm::create()
Overrides FormBase::create
File
-
modules/
cache_example/ src/ Form/ CacheExampleForm.php, line 47
Class
- CacheExampleForm
- Form with examples on how to use cache.
Namespace
Drupal\cache_example\FormCode
public static function create(ContainerInterface $container) {
// Forms that require a Drupal service or a custom service should access
// the service using dependency injection.
// @link https://www.drupal.org/node/2203931.
// Those services are passed in the $container through the static create
// method.
$form = new static();
$form->setRequestStack($container->get('request_stack'))
->setStringTranslation($container->get('string_translation'))
->setMessenger($container->get('messenger'));
$form->currentUser = $container->get('current_user');
$form->cacheBackend = $container->get('cache.default');
$form->dateFormatter = $container->get('date.formatter');
$form->fileSystem = $container->get('file_system');
return $form;
}