I have created vocabulary "Hospital" and created text and image fields like:
- Hospital Image: (machine name: field_hospital_image) // image field
- Hospital Contact: (machine name: field_hospital_contact_no_) // text field
My code is:
$vid = 'hospitals';
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadTree($vid);
foreach ($terms as $term) {
$term_data[] = [
'tid' => $term->tid,
'tname' => $term->name,
'image' => ...???.., // image field
'contact' => ...???.., // text field
];
}
Please suggest namespace also.
I alsready tried :
'contact' => $term->get('field_hospital_contact_no_')->getValue(),
and
'contact' => $term->get('field_hospital_contact_no_')->value,
Errors:
Error: Call to undefined method stdClass::get()