public function BlocksController::loadByType in Gutenberg 8
Same name and namespace in other branches
- 8.2 src/Controller/BlocksController.php \Drupal\gutenberg\Controller\BlocksController::loadByType()
Returns JSON representing the loaded blocks.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request.
string $content_type: The content type to fetch settings from.
Return value
\Symfony\Component\HttpFoundation\JsonResponse The JSON response.
1 string reference to 'BlocksController::loadByType'
File
- src/
Controller/ BlocksController.php, line 80
Class
- BlocksController
- Returns responses for our blocks routes.
Namespace
Drupal\gutenberg\ControllerCode
public function loadByType(Request $request, $content_type) {
$blockManager = \Drupal::service('plugin.manager.block');
$contextRepository = \Drupal::service('context.repository');
$config = \Drupal::service('config.factory')
->getEditable('gutenberg.settings');
$config_values = $config
->get($content_type . '_allowed_drupal_blocks');
// Get blocks definition.
$definitions = $blockManager
->getDefinitionsForContexts($contextRepository
->getAvailableContexts());
$definitions = $blockManager
->getSortedDefinitions($definitions);
$return = [];
foreach ($config_values as $key => $value) {
if ($value) {
$return[$key] = $definitions[$key];
}
}
return new JsonResponse($return);
}