0

I'm developing custom Views field handler, which renders a "Reorder" button on Commerce Line Item View. I need to access to the 'data' field, which is a serialized array. What is the best way to get serialized field data?

/**
 * Implements Reorder Line Item button field.
 */
class commerce_reorder_lineitem_handler_field_commerce_reorder_lineitem_button extends views_handler_field {

       ...

          function construct() {
            parent::construct();
            $this->real_field = 'line_item_id';
            $this->additional_fields['line_item_id'] = 'line_item_id';
            $this->additional_fields['order_id'] = 'order_id';
            $this->additional_fields['data'] = 'data';
          }

          /**
           * Render form element placeholder.
           */
          function render($values) {
            return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
          }

       ...

}

0

The views data can be altered in the handler's render() method.

  function render($values) {
    $values->commerce_line_item_data = unserialize($values->commerce_line_item_data);
    return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
  }
2
  • please elaborate - what the function does, and how it solves the problem
    – Geoff
    Jun 10 '15 at 17:18
  • Line $values->commerce_line_item_data = unserialize($values->commerce_line_item_data); added to the render() method in order to unserialize fetched data.
    – Artreaktor
    Jun 10 '15 at 19:59

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.