-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2648 from bolt/feature/post-api
Role-based API support for `POST`, `PUT` and `DELETE` operations
- Loading branch information
Showing
12 changed files
with
468 additions
and
170 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Bolt\Api; | ||
|
||
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface; | ||
use Bolt\Configuration\Config; | ||
use Bolt\Configuration\Content\FieldType; | ||
use Bolt\Entity\Content; | ||
use Bolt\Repository\FieldRepository; | ||
|
||
class ContentDataPersister implements ContextAwareDataPersisterInterface | ||
{ | ||
/** @var ContextAwareDataPersisterInterface */ | ||
private $decorated; | ||
|
||
/** @var Config */ | ||
private $config; | ||
|
||
public function __construct(ContextAwareDataPersisterInterface $decorated, Config $config) | ||
{ | ||
$this->decorated = $decorated; | ||
$this->config = $config; | ||
} | ||
|
||
public function supports($data, array $context = []): bool | ||
{ | ||
return $this->decorated->supports($data, $context); | ||
} | ||
|
||
public function persist($data, array $context = []) | ||
{ | ||
if ($data instanceof Content) { | ||
$contentTypes = $this->config->get('contenttypes'); | ||
|
||
$data->setDefinitionFromContentTypesConfig($contentTypes); | ||
|
||
foreach ($data->getFields() as $field) { | ||
$fieldDefinition = FieldType::factory($field->getName(), $data->getDefinition()); | ||
$newField = FieldRepository::factory($fieldDefinition); | ||
|
||
// todo: This works for standalone fields only. | ||
// See CollectionField.php and SetField.php | ||
$newField->setName($field->getName()); | ||
$newField->setValue($field->getValue()); | ||
|
||
$data->removeField($field); | ||
$data->addField($newField); | ||
} | ||
} | ||
|
||
$this->decorated->persist($data, $context); | ||
} | ||
|
||
public function remove($data, array $context = []) | ||
{ | ||
$this->decorated->persist($data, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.