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

Add source_module to the template. Improve code: fix comments and ord… #3858

Merged
merged 1 commit into from
Apr 10, 2019
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
27 changes: 17 additions & 10 deletions src/Command/Generate/PluginMigrateSourceCommand.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 %}