nuvoleweb / integration

This project allows a content Producer to share its content with multiple Consumers using a shared Backend.
https://www.drupal.org/project/integration
6 stars 3 forks source link

Problem exporting date with Producer #8

Closed ivanchaer closed 8 years ago

ivanchaer commented 8 years ago

Hello Antonio,

We started using the Producer module to generate JSONS from a Drupal installation.

When I export a node with a field of type Date, I get the "Illegal string offset" PHP Warning on the file:

integration/modules/integration_producer/src/FieldHandlers/DateFieldHandler.php

Where it tries to treat $value as an array, for example on the line:

$value['value2'] = isset($value['value2']) ? $value['value'] : '';

The $value variable received was not an array, but a string with the timestamp.

I manually patched the mentioned file, creating the array that it was expecting, as in:

(...)

 /**
   * {@inheritdoc}
   */
  public function processField() {

    foreach ($this->getFieldValues() as $value) {

      if (!is_array($value)) {

        $date_obj = array (
            "value"  => $value,
            "value2"  => $value,
            "date_type" => 'datestamp'
        );

        $value = $date_obj;
      }

      // Set default values if none given.
      $value['value2'] = isset($value['value2']) ? $value['value'] : '';

(...)

After this, the exported nodes have the date.

Please, find attached a feature containing the field instance and the field type, and let me know if there is any other info that could be helpful.

transport_news_date_field.zip

Many thanks, Ivan

ademarco commented 8 years ago

Thank you for reporting this @ivanchaer ! In fact we still need to properly support both datetime and datestamp fields, I'll fix this.

ademarco commented 8 years ago

@ivanchaer please check if the pushed fixes solve your issue.

ivanchaer commented 8 years ago

Thanks @ademarco, you fixed it!