Wave Profile fields stdClass::getTranslatedAttribute()

bitmap

October 20, 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!

Select One:
bobbyiliev

October 20, 05:02 PM

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!

1
Select One:
Write
Preview
Help

Markdown Basics

DevDojo uses Markdown syntax for writing posts, commments, and other content throughout the site. Below you will find some commonly used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet


Bold & Italic

Italics *asterisks*

Bold **double asterisks**


Code

Inline Code `backtick`

Code Block

```
Three back ticks and then enter your code blocks here.
```

Headers

# This is Heading 1
## This is Heading 2
### This is Heading 3
#### This is Heading 4
##### This is Heading 5

Here is an example of how each heading will looks

Heading 1

Heading 2

Heading 3

Heading 4
Heading 5

Quotes

> type a greater than sign and start typing your quote.

Links

You can add links by typing the alt text inside of [] and the link inside of (), like so:

[links](https://devdojo.com)

Images

You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the link inside of (), like so:

![alt text for image](https://cdn.devdojo.com/images/image.png)

Embedding Codepens

You can also embed a codepen pen by writing the following:

{% codepen https://codepen.io/your/pen/url %}

You may also choose the default tabs you wish to show your pen by writing the default-tab like so: (default is result)

{% codepen https://codepen.io/your/pen/url default-tab=result,html %}

That's about it. It's time to start crafting your story.

Please login, or signup to write a response.

© 2020 DevDojo LLC. All rights reserved.