public function parseEntityFields($entity_type, \stdClass $entity)
    {
        $multicolumn_field = '';
        $multicolumn_fields = array();

        foreach (clone $entity as $field => $field_value) {
            // Reset the multicolumn field if the field name does not contain a column.
            if (strpos($field, ':') === false) {
                $multicolumn_field = '';
            } elseif (strpos($field, ':', 1) !== false) {
                // Start tracking a new multicolumn field if the field name contains a ':'
                // which is preceded by at least 1 character.
                list($multicolumn_field, $multicolumn_column) = explode(':', $field);
            } elseif (empty($multicolumn_field)) {
                // If a field name starts with a ':' but we are not yet tracking a
                // multicolumn field we don't know to which field this belongs.
                throw new \Exception('Field name missing for ' . $field);
            } else {
                // Update the column name if the field name starts with a ':' and we are
                // already tracking a multicolumn field.
                $multicolumn_column = substr($field, 1);
            }

            $is_multicolumn = $multicolumn_field && $multicolumn_column;
            $field_name = $multicolumn_field ?: $field;
            if ($this->getDriver()->isField($entity_type, $field_name)) {
                // Split up multiple values in multi-value fields.
                $values = array();
                foreach (str_getcsv($field_value) as $key => $value) {
                    $value = trim($value);
                    $columns = $value;
                    // Split up field columns if the ' - ' separator is present.
                    if (strstr($value, ' - ') !== false) {
                        $columns = array();
                        foreach (explode(' - ', $value) as $column) {
                            // Check if it is an inline named column.
                            if (!$is_multicolumn && strpos($column, ': ', 1) !== false) {
                                list ($key, $column) = explode(': ', $column);
                                $columns[$key] = $column;
                            } else {
                                $columns[] = $column;
                            }
                        }
                    }
                    // Use the column name if we are tracking a multicolumn field.
                    if ($is_multicolumn) {
                        $multicolumn_fields[$multicolumn_field][$key][$multicolumn_column] = $columns;
                        unset($entity->$field);
                    } else {
                        $values[] = $columns;
                    }
                }
                // Replace regular fields inline in the entity after parsing.
                if (!$is_multicolumn) {
                    $entity->$field_name = $values;
                    // Don't specify any value if the step author has left it blank.
                    if ($field_value === '') {
                        unset($entity->$field_name);
                    }
                }
            }
        }

        // Add the multicolumn fields to the entity.
        foreach ($multicolumn_fields as $field_name => $columns) {
            // Don't specify any value if the step author has left it blank.
            if (count(array_filter($columns, function ($var) {
                return ($var !== '');
            })) > 0) {
                $entity->$field_name = $columns;
            }
        }
    }
public function parseEntityFields($entity_type, \stdClass $entity)
    {
        $multicolumn_field = '';
        $multicolumn_fields = array();

        foreach (clone $entity as $field => $field_value) {
            // Reset the multicolumn field if the field name does not contain a column.
            if (strpos($field, ':') === false) {
                $multicolumn_field = '';
            } elseif (strpos($field, ':', 1) !== false) {
                // Start tracking a new multicolumn field if the field name contains a ':'
                // which is preceded by at least 1 character.
                list($multicolumn_field, $multicolumn_column) = explode(':', $field);
            } elseif (empty($multicolumn_field)) {
                // If a field name starts with a ':' but we are not yet tracking a
                // multicolumn field we don't know to which field this belongs.
                throw new \Exception('Field name missing for ' . $field);
            } else {
                // Update the column name if the field name starts with a ':' and we are
                // already tracking a multicolumn field.
                $multicolumn_column = substr($field, 1);
            }

            $is_multicolumn = $multicolumn_field && $multicolumn_column;
            $field_name = $multicolumn_field ?: $field;
            if ($this->getDriver()->isField($entity_type, $field_name)) {
                // Split up multiple values in multi-value fields.
                $values = array();
                foreach (str_getcsv($field_value) as $key => $value) {
                    $value = trim($value);
                    $columns = $value;
                    // Split up field columns if the ' - ' separator is present.
                    if (strstr($value, ' - ') !== false) {
                        $columns = array();
                        foreach (explode(' - ', $value) as $column) {
                            // Check if it is an inline named column.
                            if (!$is_multicolumn && strpos($column, ': ', 1) !== false) {
                                list ($key, $column) = explode(': ', $column);
                                $columns[$key] = $column;
                            } else {
                                $columns[] = $column;
                            }
                        }
                    }
                    // Use the column name if we are tracking a multicolumn field.
                    if ($is_multicolumn) {
                        $multicolumn_fields[$multicolumn_field][$key][$multicolumn_column] = $columns;
                        unset($entity->$field);
                    } else {
                        $values[] = $columns;
                    }
                }
                // Replace regular fields inline in the entity after parsing.
                if (!$is_multicolumn) {
                    $entity->$field_name = $values;
                    // Don't specify any value if the step author has left it blank.
                    if ($field_value === '') {
                        unset($entity->$field_name);
                    }
                }
            }
        }

        // Add the multicolumn fields to the entity.
        foreach ($multicolumn_fields as $field_name => $columns) {
            // Don't specify any value if the step author has left it blank.
            if (count(array_filter($columns, function ($var) {
                return ($var !== '');
            })) > 0) {
                $entity->$field_name = $columns;
            }
        }
    }
public function parseEntityFields ( $ entity_type , \ stdClass $ entity ) { $ multicolumn_field = '' ; $ multicolumn_fields = array ( ) ; foreach ( clone $ entity as $ field => $ field_value ) { // Reset the multicolumn field if the field name does not contain a column. if ( strpos ( $ field , ':' ) === false ) { $ multicolumn_field = '' ; } elseif ( strpos ( $ field , ':' , 1 ) !== false ) { // Start tracking a new multicolumn field if the field name contains a ':' // which is preceded by at least 1 character. list ( $ multicolumn_field , $ multicolumn_column ) = explode ( ':' , $ field ) ; } elseif ( empty ( $ multicolumn_field ) ) { // If a field name starts with a ':' but we are not yet tracking a // multicolumn field we don't know to which field this belongs. throw new \ Exception ( 'Field name missing for ' . $ field ) ; } else { // Update the column name if the field name starts with a ':' and we are // already tracking a multicolumn field. $ multicolumn_column = substr ( $ field , 1 ) ; } $ is_multicolumn = $ multicolumn_field && $ multicolumn_column ; $ field_name = $ multicolumn_field ? : $ field ; if ( $ this -> getDriver ( ) -> isField ( $ entity_type , $ field_name ) ) { // Split up multiple values in multi-value fields. $ values = array ( ) ; foreach ( str_getcsv ( $ field_value ) as $ key => $ value ) { $ value = trim ( $ value ) ; $ columns = $ value ; // Split up field columns if the ' - ' separator is present. if ( strstr ( $ value , ' - ' ) !== false ) { $ columns = array ( ) ; foreach ( explode ( ' - ' , $ value ) as $ column ) { // Check if it is an inline named column. if ( ! $ is_multicolumn && strpos ( $ column , ': ' , 1 ) !== false ) { list ( $ key , $ column ) = explode ( ': ' , $ column ) ; $ columns [ $ key ] = $ column ; } else { $ columns [ ] = $ column ; } } } // Use the column name if we are tracking a multicolumn field. if ( $ is_multicolumn ) { $ multicolumn_fields [ $ multicolumn_field ] [ $ key ] [ $ multicolumn_column ] = $ columns ; unset ( $ entity -> $ field ) ; } else { $ values [ ] = $ columns ; } } // Replace regular fields inline in the entity after parsing. if ( ! $ is_multicolumn ) { $ entity -> $ field_name = $ values ; // Don't specify any value if the step author has left it blank. if ( $ field_value === '' ) { unset ( $ entity -> $ field_name ) ; } } } } // Add the multicolumn fields to the entity. foreach ( $ multicolumn_fields as $ field_name => $ columns ) { // Don't specify any value if the step author has left it blank. if ( count ( array_filter ( $ columns , function ( $ var ) { return ( $ var !== '' ) ; } ) ) > 0 ) { $ entity -> $ field_name = $ columns ; } } }
Parses the field values and turns them into the format expected by Drupal.

Multiple values in a single field must be separated by commas. Wrap the
field value in double quotes in case it should contain a comma.

Compound field properties are identified using a ':' operator, either in
the column heading or in the cell. If multiple properties are present in a
single cell, they must be separated using ' - ', and values should not
contain ':' or ' - '.

Possible formats for the values:
A
A, B, "a value, containing a comma"
A - B
x: A - y: B
A - B, C - D, "E - F"
x: A - y: B,  x: C - y: D,  "x: E - y: F"

See field_handlers.feature for examples of usage.

@param string $entity_type
The entity type.
@param \stdClass $entity
An object containing the entity properties and fields as properties.

@throws \Exception
Thrown when a field name is invalid.
Parses the field values and turns them into the format expected by Drupal .