Skip to content

Commit

Permalink
EZP-30172: Cannot edit Content Type with ezobjectrelation with delete…
Browse files Browse the repository at this point in the history
…d starting location (#279)
  • Loading branch information
adamwojs authored and Łukasz Serwatka committed Feb 27, 2019
1 parent 07b0a8d commit 5d543a0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bundle/Resources/config/form_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ services:
EzSystems\RepositoryForms\Form\Type\SwitcherType: ~

EzSystems\RepositoryForms\Form\Type\FieldType\BinaryBaseFieldType: ~

EzSystems\RepositoryForms\Form\Type\LocationType: ~
4 changes: 2 additions & 2 deletions lib/FieldType/Mapper/RelationFormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use EzSystems\RepositoryForms\Data\Content\FieldData;
use EzSystems\RepositoryForms\Data\FieldDefinitionData;
use EzSystems\RepositoryForms\Form\Type\FieldType\RelationFieldType;
use EzSystems\RepositoryForms\Form\Type\LocationType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand All @@ -21,7 +21,7 @@ class RelationFormMapper extends AbstractRelationFormMapper
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data)
{
$fieldDefinitionForm
->add('selectionRoot', HiddenType::class, [
->add('selectionRoot', LocationType::class, [
'required' => false,
'property_path' => 'fieldSettings[selectionRoot]',
'label' => 'field_definition.ezobjectrelation.selection_root',
Expand Down
4 changes: 2 additions & 2 deletions lib/FieldType/Mapper/RelationListFormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use EzSystems\RepositoryForms\Data\Content\FieldData;
use EzSystems\RepositoryForms\Data\FieldDefinitionData;
use EzSystems\RepositoryForms\Form\Type\FieldType\RelationListFieldType;
use EzSystems\RepositoryForms\Form\Type\LocationType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
Expand All @@ -22,7 +22,7 @@ class RelationListFormMapper extends AbstractRelationFormMapper
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data)
{
$fieldDefinitionForm
->add('selectionDefaultLocation', HiddenType::class, [
->add('selectionDefaultLocation', LocationType::class, [
'required' => false,
'property_path' => 'fieldSettings[selectionDefaultLocation]',
'label' => 'field_definition.ezobjectrelationlist.selection_default_location',
Expand Down
56 changes: 56 additions & 0 deletions lib/Form/Type/LocationType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\RepositoryForms\Form\Type;

use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
use eZ\Publish\API\Repository\LocationService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;

class LocationType extends AbstractType
{
/** @var \eZ\Publish\API\Repository\LocationService */
private $locationService;

/**
* @param \eZ\Publish\API\Repository\LocationService $locationService
*/
public function __construct(LocationService $locationService)
{
$this->locationService = $locationService;
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$view->vars['destination_location'] = null;

if ($view->vars['value']) {
try {
$view->vars['destination_location'] = $this->locationService->loadLocation(
(int)$view->vars['value']
);
} catch (NotFoundException | UnauthorizedException $e) {
}
}
}

/**
* {@inheritdoc}
*/
public function getParent(): string
{
return HiddenType::class;
}
}

0 comments on commit 5d543a0

Please # to comment.