Skip to content
New issue

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

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

Already on GitHub? # to your account

EZEE-3191: Fixed incomplete draft transition through Workflow with publish action #27

Merged
merged 2 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/lib/Content/View/Builder/AbstractContentViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace EzSystems\EzPlatformContentForms\Content\View\Builder;

use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\Repository;
use eZ\Publish\API\Repository\Values\Content\Language;
use eZ\Publish\API\Repository\Values\Content\Location;
Expand Down Expand Up @@ -46,14 +47,18 @@ abstract class AbstractContentViewBuilder
/** @var \eZ\Publish\Core\Helper\FieldsGroups\FieldsGroupsList */
private $fieldsGroupsList;

/** @var \eZ\Publish\API\Repository\ContentService */
protected $contentService;

public function __construct(
Repository $repository,
Configurator $viewConfigurator,
ParametersInjector $viewParametersInjector,
ActionDispatcherInterface $contentActionDispatcher,
UserLanguagePreferenceProviderInterface $languagePreferenceProvider,
ConfigResolverInterface $configResolver,
FieldsGroupsList $fieldsGroupsList
FieldsGroupsList $fieldsGroupsList,
ContentService $contentService
) {
$this->repository = $repository;
$this->viewConfigurator = $viewConfigurator;
Expand All @@ -62,6 +67,7 @@ public function __construct(
$this->languagePreferenceProvider = $languagePreferenceProvider;
$this->configResolver = $configResolver;
$this->fieldsGroupsList = $fieldsGroupsList;
$this->contentService = $contentService;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/lib/Content/View/Builder/ContentEditViewBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use eZ\Publish\Core\MVC\Symfony\View\Builder\ViewBuilder;
use EzSystems\EzPlatformContentForms\Content\View\ContentEditSuccessView;
use EzSystems\EzPlatformContentForms\Content\View\ContentEditView;
use Symfony\Component\Form\FormError;

/**
* Builds ContentEditView objects.
Expand Down Expand Up @@ -89,6 +90,22 @@ public function buildView(array $parameters)
}
}

if ($parameters['validate'] && !$form->isSubmitted()) {
$validationErrors = $this->contentService->validate(
$content->getVersionInfo(), [
'content' => $content,
]
);

foreach ($validationErrors as $fieldIdentifier => $validationErrorLanguages) {
foreach ($validationErrorLanguages as $languageCode => $validationError) {
$form->get('fieldsData')->get($fieldIdentifier)->get('value')->addError(new FormError(
(string)$validationError->getTranslatableMessage()
));
}
}
}

$view->setContent($content);
$view->setLanguage($language);
$view->setLocation($location);
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Content/View/Filter/ContentEditViewFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ public function handleContentEditForm(FilterViewBuilderParametersEvent $event)
$contentDraft
);

$event->getParameters()->add(['form' => $form->handleRequest($request)]);
$event->getParameters()->add([
'form' => $form->handleRequest($request),
'validate' => (bool)$request->get('validate', false),
]);
}

/**
Expand Down