X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FGenerator%2FEntityContentGenerator.php;h=158c0895fe86f274983665be13f237f3f68f8d1f;hp=3c9f98cce72b7c2b62125aac24819a91a43200c1;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Generator/EntityContentGenerator.php b/vendor/drupal/console/src/Generator/EntityContentGenerator.php index 3c9f98cce..158c0895f 100644 --- a/vendor/drupal/console/src/Generator/EntityContentGenerator.php +++ b/vendor/drupal/console/src/Generator/EntityContentGenerator.php @@ -8,9 +8,9 @@ namespace Drupal\Console\Generator; use Drupal\Console\Core\Generator\Generator; +use Drupal\Console\Core\Utils\TwigRenderer; use Drupal\Console\Extension\Manager; use Drupal\Console\Utils\Site; -use Drupal\Console\Core\Utils\TwigRenderer; class EntityContentGenerator extends Generator { @@ -25,8 +25,8 @@ class EntityContentGenerator extends Generator protected $site; /** - * @var TwigRenderer -*/ + * @var TwigRenderer + */ protected $twigrenderer; protected $io; @@ -53,163 +53,158 @@ class EntityContentGenerator extends Generator $this->io = $io; } - /** - * Generator Entity. - * - * @param string $module Module name - * @param string $entity_name Entity machine name - * @param string $entity_class Entity class name - * @param string $label Entity label - * @param string $base_path Base path - * @param string $is_translatable Translation configuration - * @param string $bundle_entity_type (Config) entity type acting as bundle - * @param bool $revisionable Revision configuration + * {@inheritdoc} */ - public function generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_type = null, $revisionable = false) + public function generate(array $parameters) { - $parameters = [ - 'module' => $module, - 'entity_name' => $entity_name, - 'entity_class' => $entity_class, - 'label' => $label, - 'bundle_entity_type' => $bundle_entity_type, - 'base_path' => $base_path, - 'is_translatable' => $is_translatable, - 'revisionable' => $revisionable, - ]; + $module = $parameters['module']; + $entity_name = $parameters['entity_name']; + $entity_class = $parameters['entity_class']; + $bundle_entity_type = $parameters['bundle_entity_type']; + $is_translatable = $parameters['is_translatable']; + $revisionable = $parameters['revisionable']; + + $moduleInstance = $this->extensionManager->getModule($module); + $moduleDir = $moduleInstance->getPath(); + $modulePath = $moduleDir . '/' . $module; + $moduleSourcePath = $moduleInstance->getSourcePath() . '/' . $entity_class; + $moduleFormPath = $moduleInstance->getFormPath() . '/' . $entity_class; + $moduleEntityPath = $moduleInstance->getEntityPath() . '/' . $entity_class; + $moduleTemplatePath = $moduleInstance->getTemplatePath() . '/'; + $moduleFileName = $modulePath . '.module'; $this->renderFile( 'module/permissions-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.permissions.yml', + $modulePath . '.permissions.yml', $parameters, FILE_APPEND ); $this->renderFile( 'module/links.menu-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.menu.yml', + $modulePath . '.links.menu.yml', $parameters, FILE_APPEND ); $this->renderFile( 'module/links.task-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.task.yml', + $modulePath . '.links.task.yml', $parameters, FILE_APPEND ); $this->renderFile( 'module/links.action-entity-content.yml.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.links.action.yml', + $modulePath . '.links.action.yml', $parameters, FILE_APPEND ); $this->renderFile( 'module/src/accesscontrolhandler-entity-content.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'AccessControlHandler.php', + $moduleSourcePath . 'AccessControlHandler.php', $parameters ); if ($is_translatable) { $this->renderFile( 'module/src/entity-translation-handler.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'TranslationHandler.php', + $moduleSourcePath . 'TranslationHandler.php', $parameters ); } $this->renderFile( 'module/src/Entity/interface-entity-content.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'Interface.php', + $moduleEntityPath . 'Interface.php', $parameters ); $this->renderFile( 'module/src/Entity/entity-content.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'.php', + $moduleEntityPath . '.php', $parameters ); $this->renderFile( 'module/src/entity-content-route-provider.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'HtmlRouteProvider.php', + $moduleSourcePath . 'HtmlRouteProvider.php', $parameters ); $this->renderFile( 'module/src/Entity/entity-content-views-data.php.twig', - $this->extensionManager->getModule($module)->getEntityPath().'/'.$entity_class.'ViewsData.php', + $moduleEntityPath . 'ViewsData.php', $parameters ); $this->renderFile( 'module/src/listbuilder-entity-content.php.twig', - $this->extensionManager->getModule($module)->getSourcePath().'/'.$entity_class.'ListBuilder.php', + $moduleSourcePath . 'ListBuilder.php', $parameters ); $this->renderFile( 'module/src/Entity/Form/entity-settings.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'SettingsForm.php', + $moduleFormPath . 'SettingsForm.php', $parameters ); $this->renderFile( 'module/src/Entity/Form/entity-content.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'Form.php', + $moduleFormPath . 'Form.php', $parameters ); $this->renderFile( 'module/src/Entity/Form/entity-content-delete.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'DeleteForm.php', + $moduleFormPath . 'DeleteForm.php', $parameters ); $this->renderFile( 'module/entity-content-page.php.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$entity_name.'.page.inc', + $moduleDir . '/' . $entity_name . '.page.inc', $parameters ); $this->renderFile( 'module/templates/entity-html.twig', - $this->extensionManager->getModule($module)->getTemplatePath().'/'.$entity_name.'.html.twig', + $moduleTemplatePath . $entity_name . '.html.twig', $parameters ); if ($revisionable) { $this->renderFile( 'module/src/Entity/Form/entity-content-revision-delete.php.twig', - $this->extensionManager->getModule($module)->getFormPath() .'/'.$entity_class.'RevisionDeleteForm.php', + $moduleFormPath . 'RevisionDeleteForm.php', $parameters ); $this->renderFile( 'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig', - $this->extensionManager->getModule($module)->getFormPath() .'/'.$entity_class.'RevisionRevertTranslationForm.php', + $moduleFormPath . 'RevisionRevertTranslationForm.php', $parameters ); $this->renderFile( 'module/src/Entity/Form/entity-content-revision-revert.php.twig', - $this->extensionManager->getModule($module)->getFormPath().'/'.$entity_class.'RevisionRevertForm.php', + $moduleFormPath . 'RevisionRevertForm.php', $parameters ); $this->renderFile( 'module/src/entity-storage.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/'.$entity_class.'Storage.php', + $moduleSourcePath . 'Storage.php', $parameters ); $this->renderFile( 'module/src/interface-entity-storage.php.twig', - $this->extensionManager->getModule($module)->getSourcePath() .'/'.$entity_class.'StorageInterface.php', + $moduleSourcePath . 'StorageInterface.php', $parameters ); $this->renderFile( 'module/src/Controller/entity-controller.php.twig', - $this->extensionManager->getModule($module)->getControllerPath() .'/'.$entity_class.'Controller.php', + $moduleInstance->getControllerPath() . '/' . $entity_class . 'Controller.php', $parameters ); } @@ -217,37 +212,36 @@ class EntityContentGenerator extends Generator if ($bundle_entity_type) { $this->renderFile( 'module/templates/entity-with-bundle-content-add-list-html.twig', - $this->extensionManager->getModule($module)->getTemplatePath().'/'.str_replace('_', '-', $entity_name).'-content-add-list.html.twig', + $moduleTemplatePath . '/' . str_replace('_', '-', $entity_name) . '-content-add-list.html.twig', $parameters ); // Check for hook_theme() in module file and warn ... - $module_filename = $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module'; // Check if the module file exists. - if (!file_exists($module_filename)) { + if (!file_exists($moduleFileName)) { $this->renderFile( 'module/module.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module . '.module', + $moduleFileName, [ 'machine_name' => $module, 'description' => '', ] ); } - $module_file_contents = file_get_contents($module_filename); + $module_file_contents = file_get_contents($moduleFileName); if (strpos($module_file_contents, 'function ' . $module . '_theme') !== false) { $this->io->warning( [ - "It looks like you have a hook_theme already declared", - "Please manually merge the two hook_theme() implementations in", - $module_filename + 'It looks like you have a hook_theme already declared', + 'Please manually merge the two hook_theme() implementations in', + $moduleFileName ] ); } $this->renderFile( 'module/src/Entity/entity-content-with-bundle.theme.php.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module', + $moduleFileName, $parameters, FILE_APPEND ); @@ -255,16 +249,16 @@ class EntityContentGenerator extends Generator if (strpos($module_file_contents, 'function ' . $module . '_theme_suggestions_' . $entity_name) !== false) { $this->io->warning( [ - "It looks like you have a hook_theme_suggestions_HOOK already declared", - "Please manually merge the two hook_theme_suggestions_HOOK() implementations in", - $module_filename + 'It looks like you have a hook_theme_suggestions_HOOK already declared', + 'Please manually merge the two hook_theme_suggestions_HOOK() implementations in', + $moduleFileName ] ); } $this->renderFile( 'module/src/Entity/entity-content-with-bundle.theme_hook_suggestions.php.twig', - $this->extensionManager->getModule($module)->getPath().'/'.$module.'.module', + $moduleFileName, $parameters, FILE_APPEND );