Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable "pluralElementType" does not exist #4732

Closed
benface opened this issue Aug 8, 2019 · 2 comments
Closed

Variable "pluralElementType" does not exist #4732

benface opened this issue Aug 8, 2019 · 2 comments

Comments

@benface
Copy link
Contributor

benface commented Aug 8, 2019

Updated Craft CMS from 3.1.34.2 to 3.2.9, and when I go to edit any field in the CP, I get this error:

Twig\Error\RuntimeError: Variable "pluralElementType" does not exist. in vendor/craftcms/cms/src/templates/_components/fieldtypes/elementfieldsettings.html:67
Stack trace:
#0 storage/runtime/compiled_templates/e0/e01541d2fc8383fcf2581104244d64a9ac1f5af27abeab042debc7f618417fbc.php(192): __TwigTemplate_e7a3506ed1a81c1f585fad8458206b77bd6a4555c6b94b3fc5c8c1a702bf8894->{closure}()
#1 vendor/twig/twig/src/Template.php(184): __TwigTemplate_e7a3506ed1a81c1f585fad8458206b77bd6a4555c6b94b3fc5c8c1a702bf8894->block_validateRelatedElementsField(Array, Array)
#2 storage/runtime/compiled_templates/e0/e01541d2fc8383fcf2581104244d64a9ac1f5af27abeab042debc7f618417fbc.php(84): Twig\Template->displayBlock('validateRelated...', Array, Array)
#3 vendor/twig/twig/src/Template.php(184): __TwigTemplate_e7a3506ed1a81c1f585fad8458206b77bd6a4555c6b94b3fc5c8c1a702bf8894->block_fieldSettings(Array, Array)
#4 storage/runtime/compiled_templates/e0/e01541d2fc8383fcf2581104244d64a9ac1f5af27abeab042debc7f618417fbc.php(56): Twig\Template->displayBlock('fieldSettings', Array, Array)
#5 vendor/twig/twig/src/Template.php(407): __TwigTemplate_e7a3506ed1a81c1f585fad8458206b77bd6a4555c6b94b3fc5c8c1a702bf8894->doDisplay(Array, Array)
#6 vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#7 vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#8 vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#9 storage/runtime/compiled_templates/97/977032a709f283ffcf121f336dc71f67a3fd0b16a7b532cfcdb142ab69db5023.php(45): craft\web\twig\Template->display(Array, Array)
#10 vendor/twig/twig/src/Template.php(407): __TwigTemplate_1f5b57111392824a7917ea06092800ac32da1bbcad10834669784cc8435255b2->doDisplay(Array, Array)
#11 vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#12 vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#13 vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#14 vendor/twig/twig/src/Template.php(392): craft\web\twig\Template->display(Array)
#15 vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#16 vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#17 vendor/craftcms/cms/src/web/View.php(344): Twig\Environment->render('_module/fields/...', Array)
#18 module/fields/entries-as/EntriesAsField.php(56): craft\web\View->renderTemplate('_module/fields/...', Array)
#19 vendor/craftcms/cms/src/fields/Matrix.php(961): module\fields\EntriesAsField->getSettingsHtml()
#20 vendor/craftcms/cms/src/fields/Matrix.php(364): craft\fields\Matrix->_getFieldOptionsForConfigurator()
#21 vendor/twig/twig/src/Extension/CoreExtension.php(1485): craft\fields\Matrix->getSettingsHtml()
#22 vendor/craftcms/cms/src/helpers/Template.php(79): twig_get_attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\fields\Matrix), 'getSettingsHtml', Array, 'method', false, false)
#23 storage/runtime/compiled_templates/3f/3f685b17a304458f2061d0f437df9cdbe752695f0b7ab2e9aca502c54d62762d.php(268): craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\fields\Matrix), 'getSettingsHtml', Array, 'method')
#24 vendor/twig/twig/src/Template.php(184): __TwigTemplate_e5db564bba7db95cb92634922f77ed02732ffe08b415dc3c76dae0eb04ee069d->block_content(Array, Array)
#25 storage/runtime/compiled_templates/d4/d4be2abfeed0aaff0b8066e3b02e708aaa4830f2a27e241699f19b1d1b0518b2.php(688): Twig\Template->displayBlock('content', Array, Array)
#26 vendor/twig/twig/src/Template.php(184): __TwigTemplate_7251f8ab8d88049460a352fd7ab90acf300a561b82d735fb31eac1fe350ff7c2->block_main(Array, Array)
#27 storage/runtime/compiled_templates/d4/d4be2abfeed0aaff0b8066e3b02e708aaa4830f2a27e241699f19b1d1b0518b2.php(561): Twig\Template->displayBlock('main', Array, Array)
#28 vendor/twig/twig/src/Template.php(184): __TwigTemplate_7251f8ab8d88049460a352fd7ab90acf300a561b82d735fb31eac1fe350ff7c2->block_body(Array, Array)
#29 storage/runtime/compiled_templates/91/9150ff84bf13b74184e5ea3ba5179808f1dc28ac0fb6a6319a900bc3e5b732f7.php(74): Twig\Template->displayBlock('body', Array, Array)
#30 vendor/twig/twig/src/Template.php(407): __TwigTemplate_f10a00dda1a8b2d73f90d5769a307cc3411559b8131c26722d5e4e0e4917fea4->doDisplay(Array, Array)
#31 vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#32 vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#33 vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#34 storage/runtime/compiled_templates/df/df788669d235ce08a01bed691c7e58d7ac8cf1fe4b0a5707bfff7d3a6bb6f7b7.php(54): craft\web\twig\Template->display(Array, Array)
#35 vendor/twig/twig/src/Template.php(407): __TwigTemplate_e4af2ea1cebc308985eca4284c3fa4b01b9fe273cb1a89b15aebfb927197fb74->doDisplay(Array, Array)
#36 vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#37 vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#38 vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#39 storage/runtime/compiled_templates/d4/d4be2abfeed0aaff0b8066e3b02e708aaa4830f2a27e241699f19b1d1b0518b2.php(116): craft\web\twig\Template->display(Array, Array)
#40 vendor/twig/twig/src/Template.php(407): __TwigTemplate_7251f8ab8d88049460a352fd7ab90acf300a561b82d735fb31eac1fe350ff7c2->doDisplay(Array, Array)
#41 vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#42 vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#43 vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#44 storage/runtime/compiled_templates/3f/3f685b17a304458f2061d0f437df9cdbe752695f0b7ab2e9aca502c54d62762d.php(109): craft\web\twig\Template->display(Array, Array)
#45 vendor/twig/twig/src/Template.php(407): __TwigTemplate_e5db564bba7db95cb92634922f77ed02732ffe08b415dc3c76dae0eb04ee069d->doDisplay(Array, Array)
#46 vendor/craftcms/cms/src/web/twig/Template.php(52): Twig\Template->displayWithErrorHandling(Array, Array)
#47 vendor/twig/twig/src/Template.php(380): craft\web\twig\Template->displayWithErrorHandling(Array, Array)
#48 vendor/craftcms/cms/src/web/twig/Template.php(34): Twig\Template->display(Array, Array)
#49 vendor/twig/twig/src/Template.php(392): craft\web\twig\Template->display(Array)
#50 vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
#51 vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#52 vendor/craftcms/cms/src/web/View.php(344): Twig\Environment->render('settings/fields...', Array)
#53 vendor/craftcms/cms/src/web/View.php(394): craft\web\View->renderTemplate('settings/fields...', Array)
#54 vendor/craftcms/cms/src/web/Controller.php(243): craft\web\View->renderPageTemplate('settings/fields...', Array)
#55 vendor/craftcms/cms/src/controllers/FieldsController.php(245): craft\web\Controller->renderTemplate('settings/fields...', Array)
#56 [internal function]: craft\controllers\FieldsController->actionEditField(25, Object(craft\fields\Entries), '3')
#57 vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#58 vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#59 vendor/craftcms/cms/src/web/Controller.php(187): yii\base\Controller->runAction('edit-field', Array)
#60 vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('edit-field', Array)
#61 vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('fields/edit-fie...', Array)
#62 vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('fields/edit-fie...', Array)
#63 vendor/craftcms/cms/src/web/Application.php(284): yii\web\Application->handleRequest(Object(craft\web\Request))
#64 vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#65 public/index.php(21): yii\base\Application->run()
#66 {main}

Additional info

  • Craft version: 3.2.9
  • PHP version: 7.3.7
  • Database driver & version: MySQL 5.7.26
  • Plugins & versions: All disabled
@brandonkelly
Copy link
Member

Looks like this is originating from module/fields/entries-as/EntriesAsField.php, line 56.

Without seeing your code, I assume that EntriesAsField is an extension of BaseRelationField, and you’re overriding getSettingsHtml() from there, but you’re not calling parent::getSettingsHtml(), so you’re not getting the new pluralElementType variable that BaseRelationField::getSettingsHtml() is passing as of Craft 3.2.

If you are overriding getSettingsHtml() just to customize which template is rendered, then you can remove it entirely, and add this to the top of your class:

protected $settingsTemplate = 'your/custom/template/path';

If you are overriding it because you (also?) needed to modify the variables passed to the template, then leave the method in-place for now, but add this to the variables array:

If that’s right, then you should be able to fix this by including this in your variable array:

'pluralElementType' => $elementType::pluralDisplayName(),

I just added a new settingsTemplateVariables() method to BaseRelationField for the next release, so in the future, you can clean up your code by overriding that method instead of getSettingsHtml():

protected function settingsTemplateVariables(): array
{
    $variables = parent::settingsTemplateVariables();

    // Add custom variables here...
    // ...

    return $variables;
}

That will future-proof your code a little better, as you’ll always get any new variables that Craft ends up adding.

@benface
Copy link
Contributor Author

benface commented Aug 8, 2019

Ah, my bad... should have checked the log for Module or something. Thank you for the nice explanation @brandonkelly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants