Wave Profile fields stdClass::getTranslatedAttribute()

Solved
bitmap

Oct 20th, 2020 04:05 PM

Hey 👋

When I try to add additional fields to the user profiles as described in video number 4 here:

https://devdojo.com/course/wave

I get this error for the simple text fields:

Call to undefined method stdClass::getTranslatedAttribute() (View: /var/www/html/vendor/tcg/voyager/resources/views/formfields/text.blade.php)

I'm adding the following:

			<div class="uk-margin-top">
		        <label class="uk-form-label">Facebook</label>
				<div class="uk-form-controls">
					{!! profile_field('text', 'facebook') !!}
				</div>
			</div>

and I have the website defined in the wave.php config already.

Any ideas on how to fix that? I could use the text area instead but I really want to have text input fields for such things!

bobbyiliev

Oct 20th, 2020 05:02 PM

Best Answer

Hey,

To get this working you can change the wave/src/Helpers/global.php file with the following:

<?php

if (!class_exists('ThemeOptionConvertible')) {
    class ThemeOptionConvertible
    {
        public function toObject() {
            $array = (array)$this;

            return (object)$array;
        }
    }
}

if (!class_exists('ThemeOptionHelper')) {
    class ThemeOptionHelper extends ThemeOptionConvertible
    {
        public $required = false;
        public $field;
        public $type;
        public $details;
        public $display_name;
        public $options = [];

        public static function create($type, $field, $details, $display_name, $required = 0, $options = []) {
            $result = new ThemeOptionHelper();
            $result->type = $type;
            $result->field = $field;
            $result->details = $details;
            $result->display_name = $display_name;
            $result->required = $required;
            $result->options = $options;

            return $result;
        }

        public function getTranslatedAttribute($attribute) {
			if ($attribute == 'display_name') {
				$attribute = '';
			}
            return $attribute;
        }
    }
}

if (!function_exists('wave_key_value')){

	function wave_key_value($type, $key, $content = '', $details = '', $placeholder = '', $required = 0){

		$row = ThemeOptionHelper::create($type, $key, $details, $placeholder, $required);
		$dataTypeContent = (object)[$key => $content];
		$type = '<input type="hidden" value="' . $type . '" name="' . $key . '_type__wave_keyvalue">';
		return app('voyager')->formField($row, '', $dataTypeContent) . $type;

	}

}

if (!function_exists('profile_field')){

	function profile_field($type, $key){

		$value = auth()->user()->profile($key);
		if($value){
			return wave_key_value($type, $key, $value);
		} else {
			return wave_key_value($type, $key);
		}

	}

}

if(!function_exists('stringToColorCode')){

	function stringToColorCode($str) {
	  $code = dechex(crc32($str));
	  $code = substr($code, 0, 6);
	  return $code;
	}

}

Let me know how it goes!

Report
4
drosossavvas

Dec 15th, 2020 07:58 AM

I had the same problem and this code worked. I suggest to include it in your next update.