You are here

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

Same name and namespace in other branches
  1. 3.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

config_entity_example/src/Form/RobotFormBase.php, line 59

Class

RobotFormBase
Class RobotFormBase.

Namespace

Drupal\config_entity_example\Form

Code

public static function create(ContainerInterface $container) {
  $form = new static($container
    ->get('entity_type.manager')
    ->getStorage('robot'));
  $form
    ->setMessenger($container
    ->get('messenger'));
  return $form;
}