verbb / expanded-singles

Craft CMS plugin to list Singles in the sidebar when editing Entries.
MIT License
53 stars 6 forks source link

Settings Page does not render #26

Closed timoschwarzer closed 4 years ago

timoschwarzer commented 4 years ago

Hi there! Unfortunately, I cannot access the settings (/admin/expanded-singles/settings) page. I tried to investigate but I didn't find a solution yet. I'm sure someone knows what's happening here better than me...

Twig\Error\RuntimeError: Variable "settings" does not exist. in /app/vendor/verbb/expanded-singles/src/templates/settings.html:25
Stack trace:
#0 /app/storage/runtime/compiled_templates/1a/1a102946cc7b9669d7474d60825b04638a290e48f871ad6a35815010b7a0d7e7.php(84): __TwigTemplate_a5ba8b2093b807e17d0eda0c02dacb7ceaf626e09026ecfb260848388bb09abb->{closure}()
#1 /app/vendor/twig/twig/src/Template.php(184): __TwigTemplate_a5ba8b2093b807e17d0eda0c02dacb7ceaf626e09026ecfb260848388bb09abb->block_blockContent(Array, Array)
#2 /app/storage/runtime/compiled_templates/8e/8e1e8fc7e42b4565427aec33c869a42fcd8ac8ea0bc28b92166a164a02e9b0a9.php(53): Twig\Template->displayBlock('blockContent', Array, Array)
#3 /app/vendor/twig/twig/src/Template.php(407): __TwigTemplate_623e74165aa83a2ee6b205f5a8f46a02226d73bb4adfa5d9e252b02230689494->doDisplay(Array, Array)
#4 /app/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#5 /app/storage/runtime/compiled_templates/1a/1a102946cc7b9669d7474d60825b04638a290e48f871ad6a35815010b7a0d7e7.php(55): Twig\Template->display(Array, Array)
#6 /app/vendor/twig/twig/src/Template.php(407): __TwigTemplate_a5ba8b2093b807e17d0eda0c02dacb7ceaf626e09026ecfb260848388bb09abb->doDisplay(Array, Array)
#7 /app/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#8 /app/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#9 /app/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#10 /app/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#11 /app/vendor/craftcms/cms/src/web/View.php(397): Twig\Environment->render('expanded-single...', Array)
#12 /app/vendor/craftcms/cms/src/web/View.php(458): craft\web\View->renderTemplate('expanded-single...', Array)
#13 /app/vendor/craftcms/cms/src/web/Controller.php(235): craft\web\View->renderPageTemplate('expanded-single...', Array, 'cp')
#14 /app/vendor/craftcms/cms/src/controllers/TemplatesController.php(98): craft\web\Controller->renderTemplate('expanded-single...', Array)
#15 [internal function]: craft\controllers\TemplatesController->actionRender('expanded-single...', Array)
#16 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#17 /app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#18 /app/vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('render', Array)
#19 /app/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('render', Array)
#20 /app/vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('templates/rende...', Array)
#21 /app/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('templates/rende...', Array)
#22 /app/vendor/craftcms/cms/src/web/Application.php(276): yii\web\Application->handleRequest(Object(craft\web\Request))
#23 /app/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#24 /app/web/index.php(21): yii\base\Application->run()
#25 {main}

I'll keep investigating...

Additional info

engram-design commented 4 years ago

Have you tried deleting your storage/runtime folder?

timoschwarzer commented 4 years ago

Yes, I did a ./craft clear-caches/all and deleted the storage/runtime folder manually, unfortunately without success.

engram-design commented 4 years ago

I suppose editing other plugins' settings is all fine? Haven't been able to immediately replicate it here, but it looks like its not resolving to the controller, instead loading the raw settings.html file.

I wonder if you're doing anything with the usePathInfo config setting? What's your environment setup look like?

timoschwarzer commented 4 years ago

Uhm, thanks for the hint! Actually, the settings pages of my other plugins don't work, too. I disabled all of them for now to be sure it's not one of the other plugins. My setup is like this:

general.php config ```php return [ // Global settings '*' => [ // Default Week Start Day (0 = Sunday, 1 = Monday...) 'defaultWeekStartDay' => 1, // Whether generated URLs should omit "index.php" 'omitScriptNameInUrls' => true, // Control Panel trigger word 'cpTrigger' => 'admin', // The secure key Craft will use for hashing and encrypting data 'securityKey' => getenv('SECURITY_KEY'), // Whether to save the project config out to config/project.yaml // (see https://docs.craftcms.com/v3/project-config.html) 'useProjectConfigFile' => true, 'csrfTokenName' => 'XSRF-TOKEN', 'sendPoweredByHeader' => false, ], // Dev environment settings 'dev' => [ // Dev Mode (see https://craftcms.com/guides/what-dev-mode-does) 'devMode' => true, ], // Staging environment settings 'staging' => [ // Set this to `false` to prevent administrative changes from being made on staging 'allowAdminChanges' => true, ], // Production environment settings 'production' => [ // Set this to `false` to prevent administrative changes from being made on production 'allowAdminChanges' => false, ], ]; ```
.env config ``` # The environment Craft is currently running in ('dev', 'staging', 'production', etc.) ENVIRONMENT=local # The secure key Craft will use for hashing and encrypting data SECURITY_KEY=5pBB9l6HW7ujaLjB0YW5iImufzCxSc9C # The database driver that will be used ('mysql' or 'pgsql') DB_DRIVER=pgsql # The database server name or IP address (usually this is 'localhost' or '127.0.0.1') DB_SERVER=db # The database username to connect with DB_USER=postgres # The database password to connect with DB_PASSWORD=dblocal # The name of the database to select DB_DATABASE=postgres # The database schema that will be used (PostgreSQL only) DB_SCHEMA=public # The port to connect to the database with. Will default to 5432 for PostgreSQL and 3306 for MySQL. DB_PORT=5432 DEFAULT_SITE_URL=http://localhost:8000 ```
nginx config ``` server { listen 80 default_server; root /app/web; index index.html index.php; charset utf-8; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } access_log off; error_log /var/log/nginx/error.log error; sendfile off; client_max_body_size 10m; gzip on; gzip_http_version 1.0; gzip_proxied any; gzip_min_length 500; gzip_disable "MSIE [1-6]\."; gzip_types text/plain text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/javascript application/atom+xml; location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass craft:9000; # craft resolves to 127.0.0.1 in local environment fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors off; fastcgi_buffer_size 16k; fastcgi_buffers 4 16k; fastcgi_read_timeout 300; } location ~ /\.ht { deny all; } } ```

The Craft project itself is in /app in a Docker container. Container port 80 is forwarded to host port 8000 so I can access it via http://localhost:8000.

timoschwarzer commented 4 years ago

Okay, I found the issue, though I don't understand it yet.

I have a custom module (stwon-base) in my project which adds some URL rules like this in its constructor:

Craft::$app->getUrlManager()->addRules([
    'api/contact-form/locations' => 'stwon-base/contact-form/locations',
    'api/contact-form/locations/<location:.+>/departments' => 'stwon-base/contact-form/departments-by-location',
    'api/contact-form/submit' => 'stwon-base/contact-form/submit',
    'api<x:(\/.*|)>' => 'stwon-base/api/not-found', // Catchall 404 route
    'mailto' => 'stwon-base/email-obfuscation/mailto', // Email deobfuscation route
]);

What I don't understand is why this affects the plugin settings pages... Do you happen to know why this happens?

engram-design commented 4 years ago

I'm not 100% certain, but I think the rule of thumb is to not call Craft::$app->getUrlManager() directly. I think you'd be better off using some of the Craft events https://docs.craftcms.com/api/v3/craft-web-urlmanager.html#events