Commit 69bc33b3 authored by Chris Shantz's avatar Chris Shantz
Browse files

Merge branch '1.0.x' into prod/1.0.x

parents df0131cc 55be8d31
......@@ -29,7 +29,7 @@ class UwWebformFileLookup extends MigrationLookup {
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$file_components = array_keys($row->getDestinationProperty('webform_components'), 'file');
$file_components = array_keys($row->getSourceProperty('webform_components'), 'file');
// Lookup destination files in the specified migration.
foreach ($file_components as $form_key) {
......
......@@ -28,7 +28,7 @@ class UwWebformUwaddress extends MigrationLookup {
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Get form keys for all uwaddress components.
$address_components = array_keys($row->getDestinationProperty('webform_components'), 'uwaddress');
$address_components = array_keys($row->getSourceProperty('webform_components'), 'uwaddress');
// Map the address sub-components to the keys used in Webform.
$address_mapping = [
......
......@@ -397,7 +397,7 @@ class UwWebform extends D7Webform {
$new_element['#answers'] = $this->getItemsArray($extra['options']);
if (!is_array($element['value'])) {
$questions_keys = array_map('array_shift', $questions);
$questions_keys = array_values($questions);
$element['value'] = array_fill_keys($questions_keys, $element['value']);
}
break;
......@@ -546,4 +546,19 @@ class UwWebform extends D7Webform {
return $handlers;
}
/**
* {@inheritdoc}
*/
protected function getItemsArray($raw_value) {
$lines = explode("\n", $raw_value);
$lines = array_map('trim', array_filter($lines));
$items = [];
foreach ($lines as $line) {
[$key, $label] = explode('|', $line);
$items[$key] = $label;
}
return $items;
}
}
......@@ -3,8 +3,8 @@
namespace Drupal\uw_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\uw_migrate\UwWebformTrait;
use Drupal\webform_migrate\Plugin\migrate\source\d7\D7WebformSubmission;
/**
* Modified Drupal 7 webform submission source from database.
......@@ -14,30 +14,70 @@ use Drupal\webform_migrate\Plugin\migrate\source\d7\D7WebformSubmission;
* source_module = "webform",
* )
*/
class UwWebformSubmission extends D7WebformSubmission {
class UwWebformSubmission extends DrupalSqlBase {
use UwWebformTrait;
/**
* A list of webform components and their types.
*
* @var array
* {@inheritdoc}
*/
public function query() {
$query = $this->select('webform_submissions', 'wfs');
$query->fields('wfs', [
'nid',
'sid',
'uid',
'submitted',
'remote_addr',
'is_draft',
]);
return $query;
}
/**
* {@inheritdoc}
*/
protected $webformComponents = [];
public function fields() {
return [
'nid' => $this->t('Webform node Id'),
'sid' => $this->t('Webform submission Id'),
'uid' => $this->t('User Id of submitter'),
'submitted' => $this->t('Submission timestamp'),
'remote_addr' => $this->t('IP Address of submitter'),
'is_draft' => $this->t('Whether this submission is draft'),
'webform_id' => $this->t('Id to be used for Webform'),
'webform_data' => $this->t('Webform submitted data'),
'webform_uri' => $this->t('Submission uri'),
];
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$result = parent::prepareRow($row);
$row->setDestinationProperty('webform_components', $this->webformComponents);
return $result;
$nid = $row->getSourceProperty('nid');
$sid = $row->getSourceProperty('sid');
$submitted_data = $this->buildSubmittedData($sid, $row);
$row->setSourceProperty('webform_id', 'webform_' . $nid);
$row->setSourceProperty('webform_data', $submitted_data);
$row->setSourceProperty('webform_uri', '/node/' . $nid);
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['sid']['type'] = 'integer';
$ids['sid']['alias'] = 'wfs';
return $ids;
}
/**
* Build submitted data from webform submitted data table.
*/
protected function buildSubmittedData($sid) {
protected function buildSubmittedData($sid, $row) {
$query = $this->select('webform_submitted_data', 'wfsd');
$query->innerJoin('webform_component', 'wc', 'wc.nid=wfsd.nid AND wc.cid=wfsd.cid');
......@@ -73,7 +113,9 @@ class UwWebformSubmission extends D7WebformSubmission {
if (!empty($item)) {
$submitted_data[$destination_form_key] = $item;
$this->webformComponents[$destination_form_key] = $wf_submission['type'];
$components = $row->getSourceProperty('webform_components');
$components[$destination_form_key] = $wf_submission['type'];
$row->setSourceProperty('webform_components', $components);
}
}
return $submitted_data;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment