Skip to content

Commit

Permalink
Merge pull request #12 from discoverygarden/fix/move-away-from-compil…
Browse files Browse the repository at this point in the history
…er-pass

CTDA9-549: Move away from compiler pass.
  • Loading branch information
nchiasson-dgi authored Jan 23, 2024
2 parents d889a0c + 9b0250e commit 4a0eb4a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 52 deletions.
8 changes: 8 additions & 0 deletions src/Annotation/DgiStandardDerivativeExaminerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\dgi_standard_derivative_examiner\Annotation;

use Drupal\Component\Annotation\Plugin;
use Drupal\dgi_standard_derivative_examiner\TargetPluginManager;

/**
* Model plugin info.
Expand All @@ -25,4 +26,11 @@ class DgiStandardDerivativeExaminerModel extends Plugin {
*/
public string $uri;

/**
* The name of the class managing target plugins.
*
* @var string
*/
public string $targetManagerClass = TargetPluginManager::class;

}
20 changes: 0 additions & 20 deletions src/DgiStandardDerivativeExaminerServiceProvider.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/ModelTargetPluginManagerExtensionPass.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\dgi_standard_derivative_examiner\Plugin\dgi_standard_derivative_examiner;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\dgi_standard_derivative_examiner\ModelInterface;
Expand Down Expand Up @@ -35,7 +36,9 @@ abstract class ModelPluginBase extends PluginBase implements ContainerFactoryPlu
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = new static($configuration, $plugin_id, $plugin_definition);

$instance->targetPluginManager = $container->get("plugin.manager.dgi_standard_derivative_examiner.target.{$plugin_id}");
$instance->targetPluginManager = is_a($plugin_definition['targetManagerClass'], ContainerInjectionInterface::class, TRUE) ?
$plugin_definition['targetManagerClass']::create($container, $plugin_id) :
new $plugin_definition['targetManagerClass']($plugin_id);

return $instance;
}
Expand Down
15 changes: 14 additions & 1 deletion src/TargetPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

namespace Drupal\dgi_standard_derivative_examiner;

use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\dgi_standard_derivative_examiner\Annotation\DgiStandardDerivativeExaminerTarget;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Target plugin manager service.
*/
class TargetPluginManager extends DefaultPluginManager implements TargetPluginManagerInterface {
class TargetPluginManager extends DefaultPluginManager implements TargetPluginManagerInterface, ContainerInjectionInterface {

/**
* Constructor.
Expand All @@ -31,4 +33,15 @@ public function __construct(
$this->alterInfo("dgi_standard_derivative_examiner_{$type}_target_plugin_info");
}

/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container, string $type = '') : self {
return new static(
$type,
$container->get('container.namespaces'),
$container->get('module_handler'),
);
}

}

0 comments on commit 4a0eb4a

Please sign in to comment.