cakephp / bake

The Bake Command Plugin
Other
110 stars 101 forks source link

4.x - Can't bake custom view template #549

Closed davidyell closed 5 years ago

davidyell commented 5 years ago

What you did

I baked my plugin and copied across the templates as per the documentation.

~/Sites/CakePHP4 $ bin/cake bake template -f --theme=CakeBootstrap --prefix=Admin Questions view

Baking `view` view template file...

File `/Users/davidyell/Sites/CakePHP4/src/../templates/Admin/Questions/view.php` exists
Do you want to overwrite? (y/n/a/q)
[n] > a
Wrote `/Users/davidyell/Sites/CakePHP4/src/../templates/Admin/Questions/view.php`

What happened?

When I baked my templates the 'view' template was baked using the default template and not the one included in my bake theme plugin.

Things you've tried

I tried making my CakeBootstrap/templates/bake/Template/view.twig template just contain the words 'A view template', to ensure I didn't have any Twig errors.

I can generate my index, add and edit templates correctly using the same command.

Show us the code

https://github.com/davidyell/Learning-CakePHP4/tree/master/plugins/CakeBootstrap/templates/bake/Template

dereuromark commented 5 years ago

I agree that this should throw an exception with the paths it tried to find instead of silent fallback. You could debug where it tries to locate the theme. Maybe this is related to the bug I discovered that makes loading plugins behave weird: https://github.com/cakephp/cakephp/pull/13264 You could try if that core branch resolved it for you?

ADmad commented 5 years ago

I agree that this should throw an exception with the paths it tried to find instead of silent fallback.

It shouldn't. This is how themes work, if a file doesn't exist in theme then it fallbacks to default. Without this feature one would have to copy all files and go through the hassle of keeping them all up to date with core even if they want to customize only some templates.

dereuromark commented 5 years ago

Oh right - agreed. Can we in verbose output at least show which ones have been used from which side? Or is that also out of scope?

ADmad commented 5 years ago

Yeah outputting which template was used would be nice.

dereuromark commented 5 years ago

Maybe in verbose:

etc

davidyell commented 5 years ago

I've spent quite a few hours today trying to pick this one apart and I can't figure out what's wrong. I've managed to get it rendering the template name, by adding a var_dump to to BakeView::render method, and it's outputting the correct template path.

However the TemplateCommand::bake method's call to getContent is returning the core template. This made me think it's in the TemplateRenderer, but I can't understand the code there as it looks to just render a template.

markstory commented 5 years ago

I can take a look at this. I may have goofed something up when I converted from shells to commands.

markstory commented 5 years ago

I tried to reproduce this problem tonight and wasn't able to. Would you be able to composer up to get the latest changes on 4.x-dev? There was a fix applied recently for plugin iteration that may be related to this.

davidyell commented 5 years ago
09:06:57 davidyell@ukwm157 ~/Sites/CakePHP4 $ rm -rf vendor/
09:07:01 davidyell@ukwm157 ~/Sites/CakePHP4 $ rm composer.lock
09:07:08 davidyell@ukwm157 ~/Sites/CakePHP4 $ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 77 installs, 0 updates, 0 removals
  - Installing cakephp/plugin-installer (1.1.0): Loading from cache
  - Installing cakephp/chronos (2.x-dev cc91cbe): Cloning cc91cbe032 from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing psr/http-server-handler (1.0.1): Loading from cache
  - Installing psr/http-server-middleware (1.0.1): Loading from cache
  - Installing psr/http-client (1.0.0): Loading from cache
  - Installing psr/http-factory (1.0.1): Loading from cache
  - Installing zendframework/zend-diactoros (2.1.2): Loading from cache
  - Installing composer/ca-bundle (1.1.4): Loading from cache
  - Installing psr/simple-cache (1.0.1): Loading from cache
  - Installing zendframework/zend-httphandlerrunner (1.1.0): Loading from cache
  - Installing psr/log (1.1.0): Loading from cache
  - Installing aura/intl (3.0.0): Loading from cache
  - Installing cakephp/cakephp (4.x-dev 261f127): Cloning 261f12760e from cache
  - Installing symfony/polyfill-ctype (v1.11.0): Loading from cache
  - Installing symfony/polyfill-mbstring (v1.11.0): Loading from cache
  - Installing twig/twig (v2.10.0): Loading from cache
  - Installing jasny/twig-extensions (v1.2.0): Loading from cache
  - Installing aptoma/twig-markdown (3.1.0): Loading from cache
  - Installing asm89/twig-cache-extension (1.3.2): Loading from cache
  - Installing wyrihaximus/twig-view (dev-master 8190c88): Cloning 8190c88b2d from cache
  - Installing cakephp/bake (4.x-dev 2459485): Cloning 2459485b6c from cache
  - Installing squizlabs/php_codesniffer (3.4.2): Loading from cache
  - Installing phpstan/phpdoc-parser (0.3.3): Loading from cache
  - Installing slevomat/coding-standard (5.0.4): Loading from cache
  - Installing cakephp/cakephp-codesniffer (dev-next 98a131c): Cloning 98a131c07e from cache
  - Installing jdorn/sql-formatter (v1.2.17): Loading from cache
  - Installing composer/xdebug-handler (1.3.2): Loading from cache
  - Installing composer/spdx-licenses (1.5.1): Loading from cache
  - Installing symfony/filesystem (v4.2.8): Loading from cache
  - Installing symfony/process (v4.2.8): Loading from cache
  - Installing symfony/finder (v4.2.8): Loading from cache
  - Installing symfony/contracts (v1.1.0): Loading from cache
  - Installing symfony/console (v4.2.8): Loading from cache
  - Installing justinrainbow/json-schema (5.2.8): Loading from cache
  - Installing seld/phar-utils (1.0.1): Loading from cache
  - Installing seld/jsonlint (1.7.1): Loading from cache
  - Installing composer/semver (1.5.0): Loading from cache
  - Installing composer/composer (1.8.5): Loading from cache
  - Installing cakephp/debug_kit (4.x-dev 9f3278a): Cloning 9f3278a1dc from cache
  - Installing mobiledetect/mobiledetectlib (2.8.33): Loading from cache
  - Installing m1/env (2.1.2): Loading from cache
  - Installing josegonzalez/dotenv (3.2.0): Loading from cache
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/resource-operations (2.0.1): Loading from cache
  - Installing sebastian/object-reflector (1.1.1): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Loading from cache
  - Installing sebastian/object-enumerator (3.0.3): Loading from cache
  - Installing sebastian/global-state (2.0.0): Loading from cache
  - Installing sebastian/exporter (3.1.0): Loading from cache
  - Installing sebastian/environment (4.2.2): Loading from cache
  - Installing sebastian/diff (3.0.2): Loading from cache
  - Installing sebastian/comparator (3.0.2): Loading from cache
  - Installing phpunit/php-timer (2.1.1): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing phpunit/php-file-iterator (2.0.2): Loading from cache
  - Installing theseer/tokenizer (1.1.2): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-token-stream (3.0.1): Loading from cache
  - Installing phpunit/php-code-coverage (6.1.4): Loading from cache
  - Installing doctrine/instantiator (1.2.0): Loading from cache
  - Installing webmozart/assert (1.4.0): Loading from cache
  - Installing phpdocumentor/reflection-common (1.0.1): Loading from cache
  - Installing phpdocumentor/type-resolver (0.4.0): Loading from cache
  - Installing phpdocumentor/reflection-docblock (4.3.1): Loading from cache
  - Installing phpspec/prophecy (1.8.0): Loading from cache
  - Installing phar-io/version (2.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.3): Loading from cache
  - Installing myclabs/deep-copy (1.9.1): Loading from cache
  - Installing phpunit/phpunit (7.5.11): Loading from cache
  - Installing jakub-onderka/php-console-color (v0.2): Loading from cache
  - Installing jakub-onderka/php-console-highlighter (v0.4): Loading from cache
  - Installing dnoegel/php-xdg-base-dir (0.1): Loading from cache
  - Installing nikic/php-parser (v4.2.1): Loading from cache
  - Installing symfony/polyfill-php72 (v1.11.0): Loading from cache
  - Installing symfony/var-dumper (v4.2.8): Loading from cache
  - Installing psy/psysh (v0.9.9): Loading from cache
cakephp/cakephp suggests installing lib-ICU (The intl PHP library, to use Text::transliterate() or Text::slug())
cakephp/cakephp suggests installing paragonie/csp-builder (CSP builder, to use the CSP Middleware)
aptoma/twig-markdown suggests installing michelf/php-markdown (Original Markdown engine with MarkdownExtra.)
aptoma/twig-markdown suggests installing knplabs/github-api (Needed for using GitHub's Markdown engine provided through their API.)
asm89/twig-cache-extension suggests installing psr/cache-implementation (To make use of PSR-6 cache implementation via PsrCacheAdapter.)
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/event-dispatcher-implementation
symfony/contracts suggests installing symfony/http-client-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/contracts suggests installing symfony/translation-contracts-implementation
symfony/console suggests installing symfony/event-dispatcher
symfony/console suggests installing symfony/lock
m1/env suggests installing m1/vars (For loading of configs)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)
Writing lock file
Generating autoload files

Still getting the same issue. Did you checkout my repo to try and replicate this?

cleptric commented 5 years ago

@davidyell Did you already try to delete the tmp/cache/twgiView folder?

davidyell commented 5 years ago

@cleptric I did before submitting the ticket, but I haven't tried since updating my composer dependancies. Let me try...

I get the same default template baked after clearing the caches using bin/cake cache clearall. However, when I manually delete the tmp/twigView folder, my template bakes correctly. Thanks!

I'll close this one now as it's resolved my issue.

cleptric commented 5 years ago

@davidyell I'll let it open because i think we should try to invalidate the cache at least when debug is on. Maybe @markstory has a good idea 🙂

ADmad commented 5 years ago

I am all in favor of disabling twig cache for bake.

markstory commented 5 years ago

Having no cache would make things much simpler.

cleptric commented 5 years ago

I disabled the cache in #552 so I'll close the issue.

davidyell commented 5 years ago

Thanks @cleptric

tgoeminne commented 1 year ago

when overwrie a plugins bake template using the templates/plugin/BootstrapUI/bake folder it will not use the overwritten file but the original file from plugin...