Skip to content

OES-618: Provide default value for version field number if none is present #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// from the last version to increase the minor by one.
$latest_revision_id = $node_storage->getLatestRevisionId($this->revision->id());
$latest_revision = $node_storage->loadRevision($latest_revision_id);
if (empty($latest_revision->get('version')->getValue())) {
$defaultVersion = $this->getDefaultVersionItem();
$latest_revision->set('version', $defaultVersion);
}
$latest_revision->get('version')->first()->increase('minor');
$this->revision->set('version', $latest_revision->get('version')->getValue());

Expand All @@ -178,6 +182,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
*/
protected function getVersionString(RevisionableInterface $revision): string {
$version_number = $revision->get($this->versionField)->getValue();
if (empty($version_number)) {
$version_number = $this->getDefaultVersionItem();
}
$version_number = reset($version_number);

return implode('.', $version_number);
Expand All @@ -202,4 +209,20 @@ protected function getVersionField(RevisionableInterface $revision): string {
return key($version_field);
}

/**
* Returns a default version item array.
*
* @return Array
* A default version item array.
*/
protected function getDefaultVersionItem() {
return [
[
"major" => "0",
"minor" => "0",
"patch" => "0",
]
];
}

}