function RobotFormBase::create
Same name in other branches
- 8.x-1.x config_entity_example/src/Form/RobotFormBase.php \Drupal\config_entity_example\Form\RobotFormBase::create()
- 4.0.x modules/config_entity_example/src/Form/RobotFormBase.php \Drupal\config_entity_example\Form\RobotFormBase::create()
Factory method for RobotFormBase.
When Drupal builds this class it does not call the constructor directly. Instead, it relies on this method to build the new object. Why? The class constructor may take multiple arguments that are unknown to Drupal. The create() method always takes one parameter -- the container. The purpose of the create() method is twofold: It provides a standard way for Drupal to construct the object, meanwhile it provides you a place to get needed constructor parameters from the container.
In this case, we ask the container for an entity query factory. We then pass the factory to our class as a constructor parameter.
Overrides FormBase::create
File
-
modules/
config_entity_example/ src/ Form/ RobotFormBase.php, line 59
Class
- RobotFormBase
- Class RobotFormBase.
Namespace
Drupal\config_entity_example\FormCode
public static function create(ContainerInterface $container) {
$form = new static($container->get('entity_type.manager')
->getStorage('robot'));
$form->setMessenger($container->get('messenger'));
return $form;
}