Issue #2626472 by benjy: MigrateTemplateStorage should have an interface
parent
e4dcadd6e2
commit
4706f54359
|
@ -13,7 +13,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
|
|||
/**
|
||||
* Storage to access migration template configuration in enabled extensions.
|
||||
*/
|
||||
class MigrateTemplateStorage {
|
||||
class MigrateTemplateStorage implements MigrateTemplateStorageInterface {
|
||||
/**
|
||||
* Extension sub-directory containing default configuration for migrations.
|
||||
*/
|
||||
|
@ -41,13 +41,7 @@ class MigrateTemplateStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Find all migration templates with the specified tag.
|
||||
*
|
||||
* @param $tag
|
||||
* The tag to match.
|
||||
*
|
||||
* @return array
|
||||
* Any templates (parsed YAML config) that matched, keyed by the ID.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function findTemplatesByTag($tag) {
|
||||
$templates = $this->getAllTemplates();
|
||||
|
@ -63,13 +57,7 @@ class MigrateTemplateStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve a template given a specific name.
|
||||
*
|
||||
* @param string $name
|
||||
* A migration template name.
|
||||
*
|
||||
* @return NULL|array
|
||||
* A parsed migration template, or NULL if it doesn't exist.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTemplateByName($name) {
|
||||
$templates = $this->getAllTemplates();
|
||||
|
@ -77,10 +65,7 @@ class MigrateTemplateStorage {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves all migration templates belonging to enabled extensions.
|
||||
*
|
||||
* @return array
|
||||
* Array of parsed templates, keyed by the fully-qualified id.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllTemplates() {
|
||||
$templates = [];
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\migrate\MigrateTemplateStorageInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\migrate;
|
||||
|
||||
/**
|
||||
* The MigrateTemplateStorageInterface interface.
|
||||
*/
|
||||
interface MigrateTemplateStorageInterface {
|
||||
|
||||
/**
|
||||
* Find all migration templates with the specified tag.
|
||||
*
|
||||
* @param $tag
|
||||
* The tag to match.
|
||||
*
|
||||
* @return array
|
||||
* Any templates (parsed YAML config) that matched, keyed by the ID.
|
||||
*/
|
||||
public function findTemplatesByTag($tag);
|
||||
|
||||
/**
|
||||
* Retrieve a template given a specific name.
|
||||
*
|
||||
* @param string $name
|
||||
* A migration template name.
|
||||
*
|
||||
* @return NULL|array
|
||||
* A parsed migration template, or NULL if it doesn't exist.
|
||||
*/
|
||||
public function getTemplateByName($name);
|
||||
|
||||
/**
|
||||
* Retrieves all migration templates belonging to enabled extensions.
|
||||
*
|
||||
* @return array
|
||||
* Array of parsed templates, keyed by the fully-qualified id.
|
||||
*/
|
||||
public function getAllTemplates();
|
||||
|
||||
}
|
|
@ -51,7 +51,7 @@ class TemplateTest extends MigrateTestBase {
|
|||
* Tests retrieving a template by name.
|
||||
*/
|
||||
public function testGetTemplateByName() {
|
||||
/** @var \Drupal\migrate\MigrateTemplateStorage $template_storage */
|
||||
/** @var \Drupal\migrate\MigrateTemplateStorageInterface $template_storage */
|
||||
$template_storage = \Drupal::service('migrate.template_storage');
|
||||
|
||||
$expected_url = [
|
||||
|
|
|
@ -11,7 +11,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
|||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate\MigrateMessage;
|
||||
use Drupal\migrate\MigrateTemplateStorage;
|
||||
use Drupal\migrate\MigrateTemplateStorageInterface;
|
||||
use Drupal\migrate\Plugin\migrate\builder\BuilderBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -36,10 +36,10 @@ class TermNode extends BuilderBase implements ContainerFactoryPluginInterface {
|
|||
* The plugin ID.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin definition.
|
||||
* @param \Drupal\migrate\MigrateTemplateStorage $template_storage
|
||||
* @param \Drupal\migrate\MigrateTemplateStorageInterface $template_storage
|
||||
* The migration template storage handler.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateTemplateStorage $template_storage) {
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrateTemplateStorageInterface $template_storage) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->templateStorage = $template_storage;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue