1

I am attempting to retrieve a value in a Fivestar rating field using views PHP. So far nothing I have attempted has been successful.

Here is the output from print_r($data):

PHP: stdClass Object ( [entityform_created] => 1448480841 [entityform_id] => 2 [field_data_field_rating_entityform_entity_type] => entityform [_field_data] => Array ( [entityform_id] => Array ( [entity_type] => entityform [entity] => Entityform Object ( [uid] => 1 [entityType:protected] => entityform [entityInfo:protected] => Array ( [label] => Entityform Submission [entity class] => Entityform [controller class] => EntityformController [base table] => entityform [fieldable] => 1 [entity keys] => Array ( [id] => entityform_id [bundle] => type [revision] => ) [bundles] => Array ( [current_feelings_about_job] => Array ( [label] => current feelings about job [admin] => Array ( [path] => admin/structure/entityform_types/manage/%entityform_type [real path] => admin/structure/entityform_types/manage/current_feelings_about_job [bundle argument] => 4 [access arguments] => Array ( [0] => administer entityform types ) ) [rdf_mapping] => Array ( ) ) [job_test] => Array ( [label] => job test [admin] => Array ( [path] => admin/structure/entityform_types/manage/%entityform_type [real path] => admin/structure/entityform_types/manage/job_test [bundle argument] => 4 [access arguments] => Array ( [0] => administer entityform types ) ) [rdf_mapping] => Array ( ) ) ) [bundle keys] => Array ( [bundle] => type ) [view modes] => Array ( [full] => Array ( [label] => Full content [custom settings] => ) [email] => Array ( [label] => Email [custom settings] => ) [confirmation] => Array ( [label] => Confirmation [custom settings] => ) [download] => Array ( [label] => Downloads [custom settings] => ) [table] => Array ( [label] => Submissions Table [custom settings] => ) [review] => Array ( [label] => Review [custom settings] => ) [token] => Array ( [label] => Tokens [custom settings] => ) ) [label callback] => entity_class_label [uri callback] => entityform_uri [creation callback] => entityform_create [access callback] => entityform_access [module] => entityform [admin ui] => Array ( [path] => admin/structure/entityforms/list [front path] => entityform [file] => entityform.admin.inc [controller class] => EntityformUIController [menu wildcard] => %entityform ) [metadata controller class] => EntityformMetadataController [metatags] => [static cache] => 1 [field cache] => 1 [load hook] => entityform_load [translation] => Array ( ) [base table field types] => Array ( [entityform_id] => serial [type] => varchar [language] => varchar [created] => int [changed] => int [data] => blob [uid] => int [draft] => int ) [schema_fields_sql] => Array ( [base table] => Array ( [0] => entityform_id [1] => type [2] => language [3] => created [4] => changed [5] => data [6] => uid [7] => draft ) ) [token type] => entityform [configuration] => ) [idKey:protected] => entityform_id [nameKey:protected] => entityform_id [statusKey:protected] => status [defaultLabel:protected] => [wrapper:protected] => [entityform_id] => 2 [type] => current_feelings_about_job [language] => [created] => 1448480841 [changed] => 1448480841 [data] => [draft] => 0 [field_rating] => Array ( [und] => Array ( [0] => Array ( [rating] => 100 [target] => ) ) ) [field_please_tell_us_why_optiona] => Array ( [und] => Array ( [0] => Array ( [value] => good day at work [format] => [safe_value] => good day at work ) ) ) [field_job_your_industry] => Array ( [und] => Array ( [0] => Array ( [tid] => 5 ) ) ) [field_job_title] => Array ( [und] => Array ( [0] => Array ( [value] => sales [format] => [safe_value] => sales ) ) ) [rdf_mapping] => Array ( ) ) ) ) [field_field_rating] => Array ( [0] => Array ( [rendered] => Array ( [#attributes] => Array ( [class] => Array ( [0] => clearfix ) ) [#theme_wrappers] => Array ( [0] => container ) [user] => Array ( [#theme] => fivestar_formatter_percentage [#instance_settings] => Array ( [stars] => 7 [allow_clear] => 1 [allow_revote] => 1 [allow_ownvote] => 0 [target] => none [user_register_form] => ) [#display_settings] => Array ( [widget] => Array ( [fivestar_widget] => default ) [expose] => 1 [style] => user [text] => average ) [#item] => Array ( [count] => 1 [user] => 100 [average] => 100 ) ) [#access] => 1 ) [raw] => Array ( [count] => 1 [user] => 100 [average] => 100 ) ) ) ) 

The field I am attempting to retrieve data from is field_rating. Any ideas on how to accomplish this?

1

Since $data is a stdClass object which seems to contain your entityform (based on your entityform_x values), you can load it as a metadata wrapper and then get the value of it via value() method, e.g.:

$wrapper = entity_metadata_wrapper('entityform', $data->entityform_id);
$rating = $wrapper->field_rating->value();

See: Entity metadata wrappers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.