Skip to main content
improved formatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Sometimes I encounter a function public static function create with argumentscreate() in plugin classes.

For example, herefor the example in the code show in https://www.sitepoint.com/tutorial-on-using-drupal-8-plugin-derivatives-effectively/Tutorial on Using Drupal 8 Plugin Derivatives Effectively we can see it.

public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static(
      $container->get('entity.manager')->getStorage('node')
    );
  }
public static function create(ContainerInterface $container, $base_plugin_id) {
  return new static(
    $container->get('entity.manager')->getStorage('node')
  );
}

Could you clarify me, what is the purpose of that function is, for? What should example what it should do and where is itit's used?

Sometimes I encounter a function public static function create with arguments in plugin classes.

For example, here https://www.sitepoint.com/tutorial-on-using-drupal-8-plugin-derivatives-effectively/ we can see it.

public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static(
      $container->get('entity.manager')->getStorage('node')
    );
  }

Could you clarify me, what is the function for? What should it do and where is it used?

Sometimes I encounter a public static function create() in plugin classes, for the example in the code show in Tutorial on Using Drupal 8 Plugin Derivatives Effectively.

public static function create(ContainerInterface $container, $base_plugin_id) {
  return new static(
    $container->get('entity.manager')->getStorage('node')
  );
}

Could you clarify me what the purpose of that function is, for example what it should do and where it's used?

Tweeted twitter.com/StackDrupal/status/1018238623974555648
Source Link
Yakimkin Roman
  • 948
  • 1
  • 11
  • 26

What is public static function create() in plugins for?

Sometimes I encounter a function public static function create with arguments in plugin classes.

For example, here https://www.sitepoint.com/tutorial-on-using-drupal-8-plugin-derivatives-effectively/ we can see it.

public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static(
      $container->get('entity.manager')->getStorage('node')
    );
  }

Could you clarify me, what is the function for? What should it do and where is it used?