Skip to content

Commit

Permalink
EZEE-3191: Fixed incomplete draft transition through Workflow with pu…
Browse files Browse the repository at this point in the history
…blish action (#27)
  • Loading branch information
Nattfarinn authored Jun 22, 2020
1 parent 3c0d036 commit e448709
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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

0 comments on commit e448709

Please sign in to comment.