Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Oct 6, 2023
2 parents 394f57b + 55a10fd commit b8cbb42
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
34 changes: 16 additions & 18 deletions src/Fields/KeyValueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function Field($properties = [])
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$nameKey = $this->name.'[key][]';
$nameVal = $this->name.'[val][]';
$nameKey = $this->name . '[key][]';
$nameVal = $this->name . '[val][]';
$fields = [];
$keyFieldPlaceholder = $this->getKeyFieldPlaceholder();
$valueFieldPlaceholder = $this->getValueFieldPlaceholder();
Expand All @@ -93,20 +93,20 @@ public function Field($properties = [])
foreach ($this->value as $i => $v) {
if ($this->readonly) {
$fieldAttr = [
'class' => 'mventryfield mvkeyvalReadonly '.($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id().MultiValueTextField::KEY_SEP.$i,
'class' => 'mventryfield mvkeyvalReadonly ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id() . MultiValueTextField::KEY_SEP . $i,
'name' => $nameKey,
'tabindex' => $this->getAttribute('tabindex')
];

$keyField = HTML::createTag('span', $fieldAttr, Convert::raw2xml($i));
$fieldAttr['id'] = $this->id().MultiValueTextField::KEY_SEP.$v;
$fieldAttr['id'] = $this->id() . MultiValueTextField::KEY_SEP . $v;
$valField = HTML::createTag('span', $fieldAttr, Convert::raw2xml($v));
$fields[] = $keyField.$valField;
$fields[] = $keyField . $valField;
} else {
$keyField = $this->createSelectList($i, $nameKey, $this->sourceKeys, $i, $keyFieldPlaceholder);
$valField = $this->createSelectList($i, $nameVal, $this->sourceValues, $v, $valueFieldPlaceholder);
$fields[] = $keyField.' '.$valField;
$fields[] = $keyField . ' ' . $valField;
}
}
} else {
Expand All @@ -116,14 +116,12 @@ public function Field($properties = [])
if (!$this->readonly) {
$keyField = $this->createSelectList('new', $nameKey, $this->sourceKeys, '', $keyFieldPlaceholder);
$valField = $this->createSelectList('new', $nameVal, $this->sourceValues, '', $valueFieldPlaceholder);
$fields[] = $keyField.' '.$valField;
// $fields[] = $this->createSelectList('new', $name, $this->source);
$fields[] = $keyField . ' ' . $valField;
// $fields[] = $this->createSelectList('new', $name, $this->source);
}

return '<ul id="'.$this->id().'" class="multivaluefieldlist mvkeyvallist '.$this->extraClass().'"><li>'.implode(
'</li><li>',
$fields
).'</li></ul>';
return '<ul id="' . $this->id() . '" class="multivaluefieldlist mvkeyvallist ' . $this->extraClass() . '"><li>'
. implode('</li><li>', $fields) . '</li></ul>';
}

protected function createSelectList($number, $name, $values, $selected = '', $placeholder = '')
Expand All @@ -133,7 +131,7 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl
[
'selected' => $selected == '' ? 'selected' : '',
'value' => ''
],
],
''
);

Expand All @@ -147,8 +145,8 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl

if (count($values ?? [])) {
$attrs = [
'class' => 'text mventryfield mvdropdown '.($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id().MultiValueTextField::KEY_SEP.$number,
'class' => 'text mventryfield mvdropdown ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id() . MultiValueTextField::KEY_SEP . $number,
'name' => $name,
'tabindex' => $this->getAttribute('tabindex')
];
Expand All @@ -160,8 +158,8 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl
return HTML::createTag('select', $attrs, $options);
} else {
$attrs = [
'class' => 'text mventryfield mvtextfield '.($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id().MultiValueTextField::KEY_SEP.$number,
'class' => 'text mventryfield mvtextfield ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id() . MultiValueTextField::KEY_SEP . $number,
'value' => $selected,
'name' => $name,
'tabindex' => $this->getAttribute('tabindex'),
Expand Down
17 changes: 9 additions & 8 deletions src/Fields/MultiValueDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ public function Field($properties = [])
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$name = $this->name.'[]';
$name = $this->name . '[]';
$fields = [];


if ($this->value) {
foreach ($this->value as $i => $v) {
if ($this->readonly) {
$fieldAttr = [
'class' => 'mventryfield mvdropdownReadonly '.($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id().MultiValueTextField::KEY_SEP.$i,
'class' => 'mventryfield mvdropdownReadonly '
. ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id() . MultiValueTextField::KEY_SEP . $i,
'name' => $name,
'tabindex' => $this->getAttribute('tabindex')
];
Expand All @@ -74,10 +75,10 @@ public function Field($properties = [])
$fields[] = $this->createSelectList($i + 1, $name, $this->source);
}

return '<ul id="'.$this->id().'" class="multivaluefieldlist '.$this->extraClass().'"><li>'.implode(
return '<ul id="' . $this->id() . '" class="multivaluefieldlist ' . $this->extraClass() . '"><li>' . implode(
'</li><li>',
$fields
).'</li></ul>';
) . '</li></ul>';
}

public function Type()
Expand All @@ -92,7 +93,7 @@ protected function createSelectList($number, $name, $values, $selected = '')
[
'selected' => $selected == '' ? 'selected' : '',
'value' => ''
],
],
''
);

Expand All @@ -105,8 +106,8 @@ protected function createSelectList($number, $name, $values, $selected = '')
}

$attrs = [
'class' => 'mventryfield mvdropdown '.($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id().MultiValueTextField::KEY_SEP.$number,
'class' => 'mventryfield mvdropdown ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id() . MultiValueTextField::KEY_SEP . $number,
'name' => $name,
'tabindex' => $this->getAttribute('tabindex')
];
Expand Down
4 changes: 2 additions & 2 deletions src/Fields/MultiValueListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function Field($properties = [])
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$name = $this->name.'[]';
$name = $this->name . '[]';

$options = '';
if (!$this->value) {
Expand All @@ -46,7 +46,7 @@ public function Field($properties = [])
}

$attrs = [
'class' => 'mventryfield mvlistbox '.($this->extraClass() ? $this->extraClass() : ''),
'class' => 'mventryfield mvlistbox ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $name,
'tabindex' => $this->getAttribute('tabindex'),
Expand Down
16 changes: 7 additions & 9 deletions src/Fields/MultiValueTextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function Field($properties = [])
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$name = $this->name.'[]';
$name = $this->name . '[]';
$fields = [];

$attributes = [
'type' => 'text',
'class' => 'text mvtextfield mventryfield '.($this->extraClass() ? $this->extraClass() : ''),
'class' => 'text mvtextfield mventryfield ' . ($this->extraClass() ? $this->extraClass() : ''),
// 'id' => $this->id(),
'name' => $name,
// 'value' => $this->Value(),
Expand All @@ -45,7 +45,7 @@ public function Field($properties = [])
$fieldAttr = $attributes;
if ($this->value) {
foreach ($this->value as $i => $v) {
$fieldAttr['id'] = $this->id().MultiValueTextField::KEY_SEP.$i;
$fieldAttr['id'] = $this->id() . MultiValueTextField::KEY_SEP . $i;
$fieldAttr['value'] = $v;
if ($this->readonly) {
unset($fieldAttr['value']);
Expand All @@ -59,17 +59,15 @@ public function Field($properties = [])
// add an empty row
if (!$this->readonly) {
// assume next pos equals to the number of existing fields which gives index+1 in a zero-indexed list
$attributes['id'] = $this->id().MultiValueTextField::KEY_SEP.count($fields ?? []);
$attributes['id'] = $this->id() . MultiValueTextField::KEY_SEP . count($fields ?? []);
$fields[] = $this->createInput($attributes);
}

if (count($fields ?? [])) {
return '<ul id="'.$this->id().'" class="multivaluefieldlist '.$this->extraClass().'"><li>'.implode(
'</li><li>',
$fields
).'</li></ul>';
return '<ul id="' . $this->id() . '" class="multivaluefieldlist ' . $this->extraClass() . '"><li>'
. implode('</li><li>', $fields) . '</li></ul>';
} else {
return '<div id="'.$this->id().'" class="multivaluefieldlist '.$this->extraClass().'"></div>';
return '<div id="' . $this->id() . '" class="multivaluefieldlist ' . $this->extraClass() . '"></div>';
}
}

Expand Down

0 comments on commit b8cbb42

Please sign in to comment.