0

so I'm trying to implement a similar "sample request" feature like the one in Drupal Steve's tutorial. Drupal 7 Sample Request.

The issue I'm having is that I'm not sure how the field reference is made to the node title within my view. Right now the select list is being generated and is available to my webform, but the list appears unpopulated. I'm provided with an empty select list widget, but no actual options to select

The issue is that the view itself is of a custom commerce content type "posters," with a relationship set on flag, such that I'm not sure what the field reference is to get the title field from my view. Steven mentions reference the node's owner, but I'm not sure what that means. Here is the code from Steve's implementation modified to meet my needs. I basically want to know how to pull the title field out of the view of flagged items, just no idea where to find what the reference to that would be...

    function webform_hook_webform_select_options_info() {
   $items = array();
   if (function_exists('webform_hook_user_flag_sample_requests')) {
     $items['webform_hook_user_flag_sample_requests'] = array(
      'title' => t("Sample Requests (User Flag list)"),
      'options callback' => 'webform_hook_user_flag_sample_requests',
     );
   }
   return $items;
 }
 function webform_hook_user_flag_sample_requests() {
   $view = views_get_view('webform_flag_views', TRUE);
   $view->set_display('webform_options');
   $view->execute();
// dpm($view);
   $options = array();

   if ($view->result) {
     $row_class = $view->style_options['row_class'];
     $attributes = $row_class ? " class='$row_class'" : '';
     foreach($view->result as $item) {
       $options[$item->nid] = '<a' . $attributes . '>' . render($item->field_field_img[0]['rendered']) . ' ' . $item->field_title . ' (' . $item->node_title . ')' . '</a>';
     }
     dpm($item);
   }
   else {
     $options[0] = t("Nothing");
   }
   dpm($options);
   return $options;
   }

Here is the result of my dpm statement on the $item variable

(Object) stdClass
    commerce_product_title (String, 9 characters ) The Rapid
    product_id (String, 3 characters ) 354
    field_data_field_image_commerce_product_entity_type (String, 16 characters )       commerce_product
    _field_data (Array, 1 element)
    field_field_image (Array, 1 element)
    field_field_img (Array, 1 element)

I've tried most of the obvious options, but I've been hitting a brick wall.

The DPM of the $options variable only returns the a tag

... (Array, 1 element)
(String, 11 characters ) <a> ()</a>

Again, many thanks in advance.

2
  • There could be a lot of failure points here. Can you post your hook_webform_select_options_info() implementation? Are you sure $view->result is not false? It's probably more helpful to dpm($options) instead of $items. What are you returning from webform_hook_user_flag_sample_requests()? Commented May 8, 2015 at 4:08
  • No, I'm not sure the view result shouldn't be false, as above the options array was just the a-tag, the sample requests are a view of commerce products with a relationship to flag.
    – nizz0k
    Commented May 8, 2015 at 4:45

1 Answer 1

1

OK, you're just accessing the wrong (non-existent) properties. You need

foreach($view->result as $item) {
   $options[$item->product_id] = '<a' . $attributes . '>' . 
       render($item->field_field_img[0]['rendered']) .
       ' (' . $item->commerce_product_title . ')' . '</a>';
 }

I removed $item->field_title because I don't see it's equivalent in your $items. And without knowing what the field_field_img is it's impossible to tell if that will work for it as well.

1
  • So, updating NID to product_id worked, and my select list was populated with with <a> ()</a>, updating node_title resulted in the title being populated into the select list. Changing field_field_img to field_field_image, results in the image tag with full system path to the image. At least I'm on the right track
    – nizz0k
    Commented May 8, 2015 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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