Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I was struggling to get the Groups in an entity to pull and print correctly. I am trying to generate a file with the base information (fields in a group) and wrap each within a group. I am only having trouble pulling the parent groups, not the fields themselves.
<?php
<?php
// Call the used entity in a meta wrapper
$wrapper = entity_metadata_wrapper('entity', $my_entity);
Run an echo command for each field found
foreach ($wrapper->field_collection as $field_name => $value) {
$field_info = field_info_field($field_name);
$type = $field_info['type'];
if ($type == 'datetime') {
$name = date("m/d/Y", $wrapper->collection->$field_name->value(array('raw')));;
echo "
<InspecGroup>
<$type>$name</$type>
</InspecGroup>
";
}
else {
$name = $wrapper->field_collection->$field_name->value(array('raw'));
echo "
<InspecGroup>
<$type>$name</$type>
</InspecGroup>
";
}
}
?>
I'm just not real sure how to wrap this properly with each field group. Tried using a parent for each loop, but was unsuccessful. Anotherwards if we had group A we would end up with the following for each group contained in the entity:
<?php
<GroupA>
<InspecGroup>
<$type>$name</$type>
</InspecGroup>
</GroupA>
?>
Any thoughts?
Comments
Comment #1
JMOmandown CreditAttribution: JMOmandown commentedSo I have the following work around, but still struggle to pull to the label value (to name the groups correctly). It would be nice if there is a cleaner and more efficient way then grabbing the information from the DB.
Comment #2
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commented