mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 13:33:14 +00:00
This is a combination of 33 commits.
- Squashed Pull request #1730 - Squashed Pull request #1741 - Squashed Pull request #1742 - Squash merge branch 4.0 - Squashed Pull request #1744 - Squashed Pull request #1746 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed Pull request #1758 - Avoid using imagine/imagine alias as it is causing install issues - Squashed merge branch 4.0 - Squashed Pull request #1763 - Squashed merge branch 4.0 - Squash of 6 commits - Squashed merge branch 4.0 - This is a combination of 2 commits. - Squashed Pull request #1775 - Squashed Pull request #1777 - Squashed Pull request #1779 - Squashed Pull request #1780 - Squashed Pull request #1782 - Adds a Pull request template - Squased Pull request #1783 - Squash Pull request #1786 - Squashed Pull request #1796 - Squashed merge branch 4.0 - Squash Pull request #1791 - Squashed merge branch 4.0 - Squashed Pull request #1808 - Squashed Pull request #1811 - Squashed Pull request #1809
This commit is contained in:
@@ -12,8 +12,8 @@ namespace Alchemy\Phrasea\Controller\Admin;
|
||||
|
||||
use Alchemy\Phrasea\Controller\Controller;
|
||||
use Alchemy\Phrasea\Metadata\TagProvider;
|
||||
use Alchemy\Phrasea\Vocabulary\Controller as VocabularyController;
|
||||
use Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface;
|
||||
use Assert\Assertion;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
@@ -96,24 +96,57 @@ class FieldsController extends Controller
|
||||
|
||||
public function listVocabularies()
|
||||
{
|
||||
$vocabularies = VocabularyController::getAvailable($this->app);
|
||||
return $this->app->json(array_map(
|
||||
[$this, 'getVocabularyAsArray'],
|
||||
$this->fetchVocabularies()
|
||||
));
|
||||
}
|
||||
|
||||
return $this->app->json(array_map(function (ControlProviderInterface $vocabulary) {
|
||||
return [
|
||||
'type' => $vocabulary->getType(),
|
||||
'name' => $vocabulary->getName(),
|
||||
];
|
||||
}, $vocabularies));
|
||||
/**
|
||||
* @return ControlProviderInterface[]
|
||||
*/
|
||||
private function fetchVocabularies()
|
||||
{
|
||||
$vocabularies = $this->getVocabularies();
|
||||
|
||||
$instances = array_map(
|
||||
function ($type) use ($vocabularies) {
|
||||
return $vocabularies[$type];
|
||||
},
|
||||
$vocabularies->keys()
|
||||
);
|
||||
|
||||
Assertion::allIsInstanceOf($instances, ControlProviderInterface::class);
|
||||
|
||||
return $instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return ControlProviderInterface
|
||||
*/
|
||||
private function fetchVocabulary($type)
|
||||
{
|
||||
$vocabularies = $this->getVocabularies();
|
||||
|
||||
$vocabulary = $vocabularies[strtolower($type)];
|
||||
|
||||
Assertion::isInstanceOf($vocabulary, ControlProviderInterface::class);
|
||||
|
||||
return $vocabulary;
|
||||
}
|
||||
|
||||
private function getVocabularyAsArray(ControlProviderInterface $vocabulary)
|
||||
{
|
||||
return [
|
||||
'type' => $vocabulary->getType(),
|
||||
'name' => $vocabulary->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getVocabulary($type)
|
||||
{
|
||||
$vocabulary = VocabularyController::get($this->app, $type);
|
||||
|
||||
return $this->app->json([
|
||||
'type' => $vocabulary->getType(),
|
||||
'name' => $vocabulary->getName(),
|
||||
]);
|
||||
return $this->app->json($this->getVocabularyAsArray($this->fetchVocabulary($type)));
|
||||
}
|
||||
|
||||
public function searchTag(Request $request)
|
||||
@@ -293,11 +326,11 @@ class FieldsController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$vocabulary = VocabularyController::get($this->app, $data['vocabulary-type']);
|
||||
$vocabulary = $this->fetchVocabulary($data['vocabulary-type']);
|
||||
$field->setVocabularyControl($vocabulary);
|
||||
$field->setVocabularyRestricted($data['vocabulary-restricted']);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
||||
// Invalid vocabulary requested
|
||||
}
|
||||
|
||||
if ('' !== $dcesElement = (string) $data['dces-element']) {
|
||||
@@ -347,4 +380,12 @@ class FieldsController extends Controller
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ControlProviderInterface[]|\Pimple
|
||||
*/
|
||||
private function getVocabularies()
|
||||
{
|
||||
return $this->app['vocabularies'];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user