Skip to content

Commit

Permalink
Add source_module to the template. Improve code: fix comments and ord…
Browse files Browse the repository at this point in the history
…er use statements alphabetically (#3858)
  • Loading branch information
LOBsTerr committed Apr 10, 2019
1 parent a6d97a2 commit c179f09
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
27 changes: 17 additions & 10 deletions src/Command/Generate/PluginMigrateSourceCommand.php
Expand Up @@ -2,30 +2,32 @@

/**
* @file
* Contains \Drupal\Console\Command\Generate\PluginBlockCommand.
* Contains \Drupal\Console\Command\Generate\PluginMigrateSourceCommand.
*/

namespace Drupal\Console\Command\Generate;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Console\Core\Command\ContainerAwareCommand;
use Drupal\Console\Generator\PluginMigrateSourceGenerator;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Command\Shared\ArrayInputTrait;
use Drupal\Console\Command\Shared\ConfirmationTrait;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Utils\Validator;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Core\Utils\StringConverter;
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Generator\PluginMigrateSourceGenerator;
use Drupal\Console\Utils\Validator;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\ElementInfoManagerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class PluginMigrateSourceCommand extends ContainerAwareCommand
{
use ModuleTrait;
use ArrayInputTrait;
use ConfirmationTrait;
use ModuleTrait;

/**
* @var ConfigFactory
Expand Down Expand Up @@ -68,7 +70,7 @@ class PluginMigrateSourceCommand extends ContainerAwareCommand
protected $elementInfoManager;

/**
* PluginBlockCommand constructor.
* PluginMigrateSourceCommand constructor.
*
* @param ConfigFactory $configFactory
* @param ChainQueue $chainQueue
Expand Down Expand Up @@ -167,6 +169,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$alias = $input->getOption('alias');
$group_by = $input->getOption('group-by');
$fields = $input->getOption('fields');
$no_interaction = $input->getOption('no-interaction');
// Parse nested data.
if ($no_interaction) {
$fields = $this->explodeInlineArray($fields);
}

$this->generator->generate([
'module' => $module,
Expand Down
20 changes: 10 additions & 10 deletions templates/module/src/Plugin/migrate/source/source.php.twig
Expand Up @@ -17,7 +17,8 @@ use Drupal\migrate\Plugin\migrate\source\SqlBase;
* Provides a '{{class_name}}' migrate source.
*
* @MigrateSource(
* id = "{{plugin_id}}"
* id = "{{plugin_id}}",
* source_module = "{{module}}"
* )
*/
class {{class_name}} extends SqlBase {% endblock %}
Expand All @@ -26,30 +27,29 @@ class {{class_name}} extends SqlBase {% endblock %}
* {@inheritdoc}
*/
public function query() {

return $this->select('{{table}}', '{{alias}}')
->fields('{{alias}}'){% if group_by %}
->fields('{{alias}}')
{% if group_by %}
->groupBy('{{alias}}.{{group_by}}')
{% endif %};
{% endif %};
}

/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
{% for field in fields %}
'{{field.id}}' => $this->t('{{field.description}}'),
{% endfor %}
];
{% for field in fields %}
'{{field.id}}' => $this->t('{{field.description}}'),
{% endfor %}
];
return $fields;
}

/**
* {@inheritdoc}
*/
public function getIds() {
return [
];
return [];
}
{% endblock %}

0 comments on commit c179f09

Please sign in to comment.