You are here

public function YamlFormElementManager::createInstance in YAML Form 8

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id: The ID of the plugin being instantiated.

array $configuration: An array of configuration relevant to the plugin instance.

Return value

object A fully configured plugin instance.

Throws

\Drupal\Component\Plugin\Exception\PluginException If the instance cannot be created, such as if the ID is invalid.

Overrides PluginManagerBase::createInstance

3 calls to YamlFormElementManager::createInstance()
YamlFormElementManager::getElementInstance in src/YamlFormElementManager.php
Get a form element plugin instance for an element.
YamlFormElementManager::getInstances in src/YamlFormElementManager.php
Get all available form element plugin instances.
YamlFormElementManager::invokeMethod in src/YamlFormElementManager.php
Invoke a method for specific FAPI element.

File

src/YamlFormElementManager.php, line 59

Class

YamlFormElementManager
Provides a plugin manager for form element plugins.

Namespace

Drupal\yamlform

Code

public function createInstance($plugin_id, array $configuration = []) {

  // If configuration is empty create a single reusable instance for each
  // Form element plugin.
  if (empty($configuration)) {
    if (!isset($this->instances[$plugin_id])) {
      $this->instances[$plugin_id] = parent::createInstance($plugin_id, $configuration);
    }
    return $this->instances[$plugin_id];
  }
  else {
    return parent::createInstance($plugin_id, $configuration);
  }
}