From 39170921d1ab0c5ae07b11414407130b6fe07674 Mon Sep 17 00:00:00 2001 From: Nikolay Lobachev Date: Sun, 22 Apr 2018 21:03:05 +0200 Subject: [PATCH] Add warning that hook already exists, remove useless use statements, add append flag for module.views.inc file (#3814) --- src/Command/Generate/PluginViewsFieldCommand.php | 13 ++++++++++++- src/Generator/PluginViewsFieldGenerator.php | 3 ++- templates/module/module.views.inc.twig | 10 ---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Command/Generate/PluginViewsFieldCommand.php b/src/Command/Generate/PluginViewsFieldCommand.php index 7fdadeb60..6cc74c407 100644 --- a/src/Command/Generate/PluginViewsFieldCommand.php +++ b/src/Command/Generate/PluginViewsFieldCommand.php @@ -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, diff --git a/src/Generator/PluginViewsFieldGenerator.php b/src/Generator/PluginViewsFieldGenerator.php index 997162e69..8dc84e90e 100644 --- a/src/Generator/PluginViewsFieldGenerator.php +++ b/src/Generator/PluginViewsFieldGenerator.php @@ -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( diff --git a/templates/module/module.views.inc.twig b/templates/module/module.views.inc.twig index 98e755c13..c9d88cb0e 100644 --- a/templates/module/module.views.inc.twig +++ b/templates/module/module.views.inc.twig @@ -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().