2

Is there a way to loop through entityform fields? Currently I'm pulling individual form values out like this, $var = $entityform_wrapper->field_name->value();

I'd like to do something like a foreach through the entityform, but everything I've tried has failed.

Update:

I have it working. The issue I'm running into now is for Value, it showing me "array", so I have to find the value in the value array.

I looked at field_get_items, entity_metadata_field_property_get and a few other functions but haven't figured out how to get the value.

Here's what I'm doing:

$entityform = entityform_load(40);
$wrapper = entity_metadata_wrapper('entityform', $entityform);
$form = $wrapper->getPropertyInfo();

foreach ($form as $key => $value) {
echo "$key is $value \n";
} 
-1

Have you looked at the EntityWrapper getIterator method:

http://drupalcontrib.org/api/drupal/contributions%21entity%21includes%21entity.wrapper.inc/function/EntityStructureWrapper%3A%3AgetIterator/7

That should be able to get the Entities children (aka Fields) I think ... I could be wrong ... use Devel and output getIterator return value and also the getChildren values ...

| improve this answer | |
  • 1
    The have the getIterator call working, but the values are still inside an array so I get field_name_first => array, I havn't figured out how to pull the value out of the array. – JohnnyB Mar 6 '14 at 13:49
  • This is not a good answer. Outputting those objects with Devel returns huge objects full of metadata, and all the properties are protected, so in the same way that outputting the wrapper object itself is not useful, outputting the iterator is not useful. – mbomb007 Sep 18 '19 at 21:05

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.