ビューPHPを使用して Fivestar レーティングフィールドの値を取得しようとしています。これまでのところ、私が試みたことは何も成功していません。
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 ) ) ) )
私がデータを取得しようとしているフィールドはfield_ratingです。これを達成する方法に関するアイデアはありますか?
_$data
_は entityform (_entityform_x
_値に基づく)を含むと思われるstdClassオブジェクトであるため、メタデータラッパーとしてロードし、その値を取得できます。 value()
メソッド経由、例:
_$wrapper = entity_metadata_wrapper('entityform', $data->entityform_id);
$rating = $wrapper->field_rating->value();
_
参照: エンティティメタデータラッパー 。