use Atomastic\Arrays\Arrays;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Writer\Html;
use Jfcherng\Diff\DiffHelper;
'text' => self::TYPE_TEXT,
'link.url' => self::TYPE_TEXT,
],
+ 'image' => [
+ 'caption' => self::TYPE_TEXT,
+ ],
'image-box' => [
'title_text' => self::TYPE_TEXT,
'description_text' => self::TYPE_TEXTAREA,
'cube-timeline-horizontal' => [
'items' => [ // Repeater
'title' => self::TYPE_TEXT,
- 'cta_text' => self::TYPE_TEXT,
- 'cta_link.url' => self::TYPE_TEXT,
+ 'content' => self::TYPE_HTML,
],
],
'cube-testimonial-carousel' => [
// Widgets that shouldn't be translated
$this->ignored_widgets = [
- 'image',
'image-carousel',
'spacer',
'google_maps',
// Search through all data until we find the item we're looking for
foreach ($data as &$element) {
- if ($element['id'] === $element_ID && isset($element['widgetType']) && $element['widgetType'] === $widget_type) {
+ // ID check is loose because previous translation exports might have had IDs unexpectedly
+ // cast as integers, resulting in mismatches later if comparison is strict.
+ // For example: (string)'482016e2' becomes (int)48201600
+ // See: https://phpspreadsheet.readthedocs.io/en/latest/topics/accessing-cells/#excel-datatypes
+ if ($element['id'] == $element_ID && isset($element['widgetType']) && $element['widgetType'] === $widget_type) {
// Match found! Now update data...
$element = $this->update_field($element, $field_name, $contents);
for ($i = 0; $i < count($data); $i++) {
$x = $i + 2; // Offset the row number to allow for header row (i is zero-indexed but rows start from 1)
$sheet
- ->setCellValue('A' . $x, $data[$i]['id'])
+ // ID field needs to be explicitly set as a string to avoid possibility of casting as an integer,
+ // which in turn can cause weird PHP conversions to occur (eg. '482016e2' ==> 48201600)
+ ->setCellValueExplicit('A' . $x, $data[$i]['id'], DataType::TYPE_STRING)
->setCellValue('B' . $x, $data[$i]['widget'])
->setCellValue('C' . $x, $data[$i]['field'])
->setCellValue('D' . $x, $data[$i]['content'])->getStyle('D' . $x)->getAlignment()->setWrapText(true);