Skip to content

Commit

Permalink
Add warning that hook already exists, remove useless use statements, …
Browse files Browse the repository at this point in the history
…add append flag for module.views.inc file (#3814)
  • Loading branch information
LOBsTerr authored and jmolivas committed Apr 22, 2018
1 parent 1b95086 commit 3917092
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
13 changes: 12 additions & 1 deletion src/Command/Generate/PluginViewsFieldCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$module = $input->getOption('module');
$module = $this->validateModule($input->getOption('module'));
$class_name = $this->validator->validateClassName($input->getOption('class'));
$class_machine_name = $this->stringConverter->camelCaseToUnderscore($class_name);
$title = $input->getOption('title');
$description = $input->getOption('description');

$function = $module . '_views_data';
$viewsFile = $module . '.views.inc';
if ($this->extensionManager->validateModuleFunctionExist($module, $function, $viewsFile)) {
$this->getIo()->warning(
sprintf(
$this->trans('commands.generate.plugin.views.field.messages.views-data-already-implemented'),
$module
)
);
}

$this->generator->generate([
'module' => $module,
'class_machine_name' => $class_machine_name,
Expand Down
3 changes: 2 additions & 1 deletion src/Generator/PluginViewsFieldGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function generate(array $parameters)
$this->renderFile(
'module/module.views.inc.twig',
$this->extensionManager->getModule($module)->getPath() . '/' . $module . '.views.inc',
$parameters
$parameters,
FILE_APPEND
);

$this->renderFile(
Expand Down
10 changes: 0 additions & 10 deletions templates/module/module.views.inc.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@

{% block extra_info %} * Provide a custom views field data that isn't tied to any other module.{% endblock %}

{% block use_class %}
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Render\Markup;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\system\ActionConfigEntityInterface;
{% endblock %}

{% block file_methods %}
/**
* Implements hook_views_data().
Expand Down

0 comments on commit 3917092

Please sign in to comment.