Skip to content
Snippets Groups Projects

3517626: Fix circular reference error when using modeler_api.

Merged Chris Weber requested to merge issue/eca-3517626:3517626--circular-reference into 3.0.x
All threads resolved!
@@ -34,6 +34,15 @@ class Eca extends ModelOwnerBase {
Api::COMPONENT_TYPE_ELEMENT => 'action',
];
/**
* Dependency Injection container.
*
* Used for getter injection.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface|null
*/
protected ?ContainerInterface $container;
/**
* ECA events service.
*
@@ -62,20 +71,6 @@ class Eca extends ModelOwnerBase {
*/
protected ?string $documentationDomain;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->eventsService = $container->get('eca.service.event');
$instance->conditionsService = $container->get('eca.service.condition');
$instance->actionsService = $container->get('eca.service.action');
$instance->documentationDomain = $container->getParameter('eca.default_documentation_domain') ?
$container->get('config.factory')->get('eca.settings')->get('documentation_domain') :
NULL;
return $instance;
}
/**
* {@inheritdoc}
*/
@@ -104,14 +99,77 @@ class Eca extends ModelOwnerBase {
return '\Drupal\eca_ui\Form\Settings';
}
/**
* Get Dependency Injection container.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
* Current Dependency Injection container.
*/
protected function getContainer(): ContainerInterface {
if (!isset($this->container)) {
// @phpstan-ignore-next-line
$this->container = \Drupal::getContainer();
}
return $this->container;
}
/**
* ECA event plugins.
*
* @return \Drupal\eca\Service\Events
*/
protected function eventsService(): Events {
if (!isset($this->eventsService)) {
$this->eventsService = $this->getContainer()->get('eca.service.event');
}
return $this->eventsService;
}
/**
* ECA condition plugins.
*
* @return \Drupal\eca\Service\Conditions
*/
protected function conditionsService(): Conditions {
if (!isset($this->conditionsService)) {
$this->conditionsService = $this->getContainer()->get('eca.service.condition');
}
return $this->conditionsService;
}
/**
* Use the ECA event service.
*
* @return \Drupal\eca\Service\Actions
*/
protected function actionsService(): Actions {
if (!isset($this->actionsService)) {
$this->actionsService = $this->getContainer()->get('eca.service.action');
}
return $this->actionsService;
}
protected function documentationDomain(): string|null {
if (!isset($this->documentationDomain)) {
$this->documentationDomain = $this->getContainer()
->getParameter('eca.default_documentation_domain')
? $this->getContainer()
->get('config.factory')
->get('eca.settings')
->get('documentation_domain')
: NULL;
}
return $this->documentationDomain;
}
/**
* {@inheritdoc}
*/
public function availableOwnerComponents(int $type): array {
return match($type) {
Api::COMPONENT_TYPE_START => $this->eventsService->events(),
Api::COMPONENT_TYPE_CONDITION => $this->conditionsService->conditions(),
Api::COMPONENT_TYPE_ELEMENT => $this->actionsService->actions(),
Api::COMPONENT_TYPE_START => $this->eventsService()->events(),
Api::COMPONENT_TYPE_CONDITION => $this->conditionsService()->conditions(),
Api::COMPONENT_TYPE_ELEMENT => $this->actionsService()->actions(),
default => [],
};
}
@@ -130,7 +188,7 @@ class Eca extends ModelOwnerBase {
$form_state = new FormState();
try {
if ($plugin instanceof ActionInterface) {
$form = $this->actionsService->getConfigurationForm($plugin, $form_state) ?? [
$form = $this->actionsService()->getConfigurationForm($plugin, $form_state) ?? [
'error_message' => [
'#type' => 'checkbox',
'#title' => $this->t('Error in configuration form!!!'),
@@ -160,7 +218,7 @@ class Eca extends ModelOwnerBase {
* {@inheritdoc}
*/
public function pluginDocUrl(PluginInspectionInterface $plugin, string $pluginType): ?string {
if (!($domain = $this->documentationDomain)) {
if (!($domain = $this->documentationDomain())) {
return NULL;
}
$provider = $plugin->getPluginDefinition()['provider'];
Loading