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

Exception when saving User with empty Phone field #38

Closed
elvdm opened this issue Mar 7, 2018 · 2 comments
Closed

Exception when saving User with empty Phone field #38

elvdm opened this issue Mar 7, 2018 · 2 comments
Assignees
Labels

Comments

@elvdm
Copy link

elvdm commented Mar 7, 2018

I have added Sprout Fields' phone field to the User field layout, and it is set as not required.

When I save the user when the field is populated with a value, it works.
When the field is not populated with a value, I get an exception thrown:

PHP Recoverable Error – yii\base\ErrorException
Method barrelstrength\sproutbase\models\sproutfields\Phone::__toString() must return a string value

Stack trace:

2018-03-07 13:55:09 [127.0.0.1][1][8madbmg67e4fthvj3bk9fbp9st][error][yii\base\ErrorException:4096] yii\base\ErrorException: Method barrelstrength\sproutbase\models\sproutfields\Phone::__toString() must return a string value in /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/helpers/StringHelper.php:758
Stack trace:
#0 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/web/ErrorHandler.php(84): yii\base\ErrorHandler->handleError(4096, 'Method barrelst...', '/Users/emma/Sit...', 758)
#1 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/helpers/StringHelper.php(758): craft\web\ErrorHandler->handleError(4096, 'Method barrelst...', '/Users/emma/Sit...', 758, Array)
#2 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/base/Field.php(322): craft\helpers\StringHelper::toString(Object(barrelstrength\sproutbase\models\sproutfields\Phone), ' ')
#3 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/services/Content.php(236): craft\base\Field->getSearchKeywords(Object(barrelstrength\sproutbase\models\sproutfields\Phone), Object(craft\elements\User))
#4 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/services/Content.php(201): craft\services\Content->_updateSearchIndexes(Object(craft\elements\User), Object(craft\models\FieldLayout))
#5 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/services/Elements.php(455): craft\services\Content->saveContent(Object(craft\elements\User))
#6 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/controllers/UsersController.php(1101): craft\services\Elements->saveElement(Object(craft\elements\User), false)
#7 [internal function]: craft\controllers\UsersController->actionSaveUser()
#8 /Users/emma/Sites/bouwjobs/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /Users/emma/Sites/bouwjobs/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/web/Controller.php(74): yii\base\Controller->runAction('save-user', Array)
#11 /Users/emma/Sites/bouwjobs/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('save-user', Array)
#12 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/web/Application.php(237): yii\base\Module->runAction('users/save-user', Array)
#13 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/web/Application.php(445): craft\web\Application->runAction('users/save-user', Array)
#14 /Users/emma/Sites/bouwjobs/vendor/craftcms/cms/src/web/Application.php(221): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#15 /Users/emma/Sites/bouwjobs/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#16 /Users/emma/Sites/bouwjobs/web/index.php(42): yii\base\Application->run()
#17 /Users/emma/.composer/vendor/laravel/valet/server.php(147): require('/Users/emma/Sit...')
#18 {main}

Within barrelstrength\sproutbase\models\sproutfields\Phone, the __toString method is trying to return $this->international, which is set to NULL when the field is empty.
Changing this line to return (string)$this->international; appears to resolve the issue.

Thank you for this plugin by the way, it looks really useful!

@BenParizek
Copy link
Member

Thanks @elvdm.

We'll try to recreate this and get your fix into the next release.

@BenParizek BenParizek added the bug label Mar 7, 2018
@BenParizek
Copy link
Member

Fixed in v3.0.3

Thanks!

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

No branches or pull requests

3 participants