Skip to content

Conversation

@adriendupuis
Copy link
Contributor

@adriendupuis adriendupuis commented Oct 7, 2024

Question Answer
JIRA Ticket N/A
Versions master, 4.6, 3.3
Edition Experience, Commerce

FormSubmissionService::create also need the field's id
(see https://github.com/ibexa/form-builder/blob/v4.6.12/src/lib/FormSubmission/FormSubmissionService.php#L72-L80 and https://github.com/ezsystems/ezplatform-form-builder/blob/v2.3.19/src/lib/FormSubmission/FormSubmissionService.php#L74-L82 for the needed keys).

Preview: https://ez-systems-developer-documentation--2511.com.readthedocs.build/en/2511/content_management/forms/form_api/#creating-form-submissions

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

@adriendupuis adriendupuis changed the title FormSubmissionCommand.php: identifier → id Fix FormSubmissionServiceInterface::create usage Oct 7, 2024
$content = $this->contentService->loadContent(143);
$contentInfo = $content->contentInfo;

$formValue = $content->getFieldValue('form', 'eng-GB')->getFormValue();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foreach ($formValue->getFields() as $field) {dump($field->getId(), $field->getIdentifier(), $field->getName());} showed me what to use while testing this command for real.

@adriendupuis adriendupuis marked this pull request as ready for review October 7, 2024 14:22
@adriendupuis adriendupuis requested a review from barw4 October 7, 2024 14:22
@github-actions
Copy link

github-actions bot commented Oct 7, 2024

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php

docs/content_management/forms/form_api.md@17:``` php
docs/content_management/forms/form_api.md@18:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 54, 55) =]]
docs/content_management/forms/form_api.md@19:```

001⫶ $submissions = $this->formSubmissionService->loadByContent($contentInfo);

docs/content_management/forms/form_api.md@24:``` php
docs/content_management/forms/form_api.md@25:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 55, 66) =]]
docs/content_management/forms/form_api.md@26:```

001⫶ $output->writeln('Total number of submissions: ' . $submissions->getTotalCount());
002⫶ foreach ($submissions as $sub) {
003⫶ $output->write($sub->getId() . '. submitted on ');
004⫶ $output->write($sub->getCreated()->format('Y-m-d H:i:s') . ' by ');
005⫶ $output->writeln((string) $this->userService->loadUser($sub->getUserId())->getName());
006⫶ foreach ($sub->getValues() as $value) {
007⫶ $output->writeln('- ' . $value->getIdentifier() . ': ' . $value->getDisplayValue());
008⫶ }
009⫶ }

docs/content_management/forms/form_api.md@39:``` php
docs/content_management/forms/form_api.md@40:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 40, 53) =]]
docs/content_management/forms/form_api.md@41:```

001⫶ $formValue = $content->getFieldValue('form', 'eng-GB')->getFormValue();
002⫶ $data = [

code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php

docs/content_management/forms/form_api.md@17:``` php
docs/content_management/forms/form_api.md@18:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 54, 55) =]]
docs/content_management/forms/form_api.md@19:```

001⫶ $submissions = $this->formSubmissionService->loadByContent($contentInfo);

docs/content_management/forms/form_api.md@24:``` php
docs/content_management/forms/form_api.md@25:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 55, 66) =]]
docs/content_management/forms/form_api.md@26:```

001⫶ $output->writeln('Total number of submissions: ' . $submissions->getTotalCount());
002⫶ foreach ($submissions as $sub) {
003⫶ $output->write($sub->getId() . '. submitted on ');
004⫶ $output->write($sub->getCreated()->format('Y-m-d H:i:s') . ' by ');
005⫶ $output->writeln((string) $this->userService->loadUser($sub->getUserId())->getName());
006⫶ foreach ($sub->getValues() as $value) {
007⫶ $output->writeln('- ' . $value->getIdentifier() . ': ' . $value->getDisplayValue());
008⫶ }
009⫶ }

docs/content_management/forms/form_api.md@39:``` php
docs/content_management/forms/form_api.md@40:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 40, 53) =]]
docs/content_management/forms/form_api.md@41:```

001⫶ $formValue = $content->getFieldValue('form', 'eng-GB')->getFormValue();
002⫶ $data = [
003⫶            ['identifier' => 'single_line', 'name' => 'Line', 'value' => 'The name'],
004⫶ ['identifier' => 'number', 'name' => 'Number', 'value' => 123],
005⫶ ['identifier' => 'checkbox', 'name' => 'Checkbox', 'value' => 0],
003⫶            ['id' => 7, 'identifier' => 'single_line', 'name' => 'Line', 'value' => 'The name'],
004⫶ ['id' => 8, 'identifier' => 'number', 'name' => 'Number', 'value' => 123],
005⫶ ['id' => 9, 'identifier' => 'checkbox', 'name' => 'Checkbox', 'value' => 0],
006⫶        ];
007⫶
008⫶ $this->formSubmissionService->create(
009⫶ $contentInfo,
010⫶ 'eng-GB',
011⫶ $formValue,
012⫶ $data
013⫶ );

docs/content_management/forms/form_api.md@47:``` php
docs/content_management/forms/form_api.md@48:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 66, 68) =]]
docs/content_management/forms/form_api.md@49:```

001⫶ $submission = $this->formSubmissionService->loadById(29);
002⫶ $this->formSubmissionService->delete($submission);

006⫶        ];
007⫶
008⫶ $this->formSubmissionService->create(
009⫶ $contentInfo,
010⫶ 'eng-GB',
011⫶ $formValue,
012⫶ $data
013⫶ );

docs/content_management/forms/form_api.md@47:``` php
docs/content_management/forms/form_api.md@48:[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 66, 68) =]]
docs/content_management/forms/form_api.md@49:```

001⫶ $submission = $this->formSubmissionService->loadById(29);
002⫶ $this->formSubmissionService->delete($submission);

Download colorized diff

@adriendupuis adriendupuis requested a review from mnocon October 8, 2024 14:06
Copy link
Contributor

@mnocon mnocon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

My first chance to use the diff report in a real PR - it's definitely useful ❤️

@adriendupuis adriendupuis merged commit 0b4f8c2 into master Oct 14, 2024
6 checks passed
@adriendupuis adriendupuis deleted the fix-form-api-create branch October 14, 2024 12:26
adriendupuis added a commit that referenced this pull request Oct 14, 2024
* FormSubmissionCommand.php: both identifier & id are needed
* phpstan-baseline.neon: rm FormSubmissionCommandInterface::create ignore

(cherry picked from commit 0b4f8c2)
adriendupuis added a commit that referenced this pull request Oct 14, 2024
* FormSubmissionCommand.php: both identifier & id are needed
* phpstan-baseline.neon: rm FormSubmissionCommandInterface::create ignore

(cherry picked from commit 0b4f8c2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants