You are here

public function RuleComponent::createInstance in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Entity/RuleComponent.php \Drupal\rng\Entity\RuleComponent::createInstance()
  2. 8 src/Entity/RuleComponent.php \Drupal\rng\Entity\RuleComponent::createInstance()

Gets the configuration for the component.

This should only be used if the caller does not have access to dependency injection.

@todo: change @todo: common class.

Return value

when condition and action plugins have a better

\Drupal\Core\Condition\ConditionPluginBase|\Drupal\Core\Action\ConfigurableActionBase|null A condition or action plugin. Or NULL if the plugin does not exist.

Throws

\Exception If the plugin type is invalid.

Overrides RuleComponentInterface::createInstance

File

src/Entity/RuleComponent.php, line 99

Class

RuleComponent
Defines a event rule plugin instance entity: a condition or action.

Namespace

Drupal\rng\Entity

Code

public function createInstance() {
  if (in_array($this
    ->getType(), [
    'action',
    'condition',
  ])) {
    $manager = \Drupal::service('plugin.manager.' . $this
      ->getType());
    return $manager
      ->createInstance($this
      ->getPluginId(), $this
      ->getConfiguration());
  }
  else {
    throw new \Exception('Invalid RuleComponent type.');
  }
}