Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTDA9-549: Move away from compiler pass. #12

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'),
);
}

}
Loading