You are here

public function Manager::createInstance in Field Permissions 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/FieldPermissionType/Manager.php \Drupal\field_permissions\Plugin\FieldPermissionType\Manager::createInstance()

Allow the field storage to be passed into the plugin.

Parameters

string $plugin_id: The plugin ID.

array $configuration: The plugin configuration.

\Drupal\field\FieldStorageConfigInterface $field_storage: The field storage.

Return value

\Drupal\field_permissions\Plugin\FieldPermissionTypeInterface The field permission type plugin instance.

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides PluginManagerBase::createInstance

File

src/Plugin/FieldPermissionType/Manager.php, line 51

Class

Manager
Field permission type plugin manager.

Namespace

Drupal\field_permissions\Plugin\FieldPermissionType

Code

public function createInstance($plugin_id, array $configuration = [], FieldStorageConfigInterface $field_storage = NULL) {
  $plugin_definition = $this
    ->getDefinition($plugin_id);
  $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition);

  // If the plugin provides a factory method, pass the container to it.
  if (is_subclass_of($plugin_class, ContainerFactoryPluginInterface::class)) {
    $plugin = $plugin_class::create(\Drupal::getContainer(), $configuration, $plugin_id, $plugin_definition, $field_storage);
  }
  else {
    $plugin = new $plugin_class($configuration, $plugin_id, $plugin_definition, $field_storage);
  }
  return $plugin;
}