Skip to content
Snippets Groups Projects
Commit 1a611411 authored by Ramon  Serra Vasconcelos's avatar Ramon Serra Vasconcelos Committed by Stephen Lucero
Browse files

Issue #3300226 by jsricardo, ramonvasconcelos, LeoAlcci, nitin_lama,...

Issue #3300226 by jsricardo, ramonvasconcelos, LeoAlcci, nitin_lama, alexanderj, dipesh_goswami, mpaulo: \Drupal calls should be avoided in classes using dependency injection
parent 9c6b80e1
Branches
Tags
1 merge request!48Resolve #3300226 "Drupal calls should be avoided in classes using dependency injection."
......@@ -4,8 +4,9 @@ namespace Drupal\patternkit_media_library\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\media_library\MediaLibraryState;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Drupal\media_library\MediaLibraryUiBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller routines for block example routes.
......@@ -23,6 +24,36 @@ class PatternkitMediaLibraryController extends ControllerBase {
*
* @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
/**
* Block storage manager.
*
* @var \Drupal\media_library\MediaLibraryUiBuilderInterface
*/
protected MediaLibraryUiBuilder $mediaLibraryUiBuilder;
/**
* {@inheritdoc}
*/
public function __construct(MediaLibraryUiBuilder $media_library_builder) {
$this->mediaLibraryUiBuilder = $media_library_builder;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('media_library.ui_builder')
);
}
/**
* Builds the UI.
*
* @param Symfony\Component\HttpFoundation\Request $request
* The Symfony request object.
*/
public function mediaLibrary(Request $request): array {
$query = $request->query;
$ml_state = MediaLibraryState::create(
......@@ -32,13 +63,9 @@ class PatternkitMediaLibraryController extends ControllerBase {
$query->get('media_library_remaining'),
$query->get('media_library_opener_parameters', [])
);
if (!\Drupal::hasService('media_library.ui_builder')) {
throw new ServiceNotFoundException('media_library.ui_builder');
}
/** @var \Drupal\media_library\MediaLibraryUiBuilder $ml_ui_builder */
$ml_ui_builder = \Drupal::service('media_library.ui_builder');
return $ml_ui_builder->buildUi($ml_state);
return $this->mediaLibraryUiBuilder->buildUi($ml_state);
}
}
......@@ -28,6 +28,13 @@ class PatternkitController extends ControllerBase {
*/
protected EntityStorageInterface $blockStorage;
/**
* Object request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The custom pattern entity storage.
*
......@@ -65,12 +72,14 @@ class PatternkitController extends ControllerBase {
EntityStorageInterface $patternkit_block_storage,
EntityStorageInterface $patternkit_pattern_storage,
LibraryInterface $library,
ThemeHandlerInterface $theme_handler
ThemeHandlerInterface $theme_handler,
Request $request
) {
$this->blockStorage = $patternkit_block_storage;
$this->patternStorage = $patternkit_pattern_storage;
$this->library = $library;
$this->themeHandler = $theme_handler;
$this->request = $request;
}
/**
......@@ -92,7 +101,8 @@ class PatternkitController extends ControllerBase {
$entity_manager->getStorage('patternkit_block'),
$entity_manager->getStorage('patternkit_pattern'),
$library,
$theme_handler
$theme_handler,
$container->get('request_stack')
);
}
......@@ -119,7 +129,7 @@ class PatternkitController extends ControllerBase {
];
}
$content['types'] = [];
$query = \Drupal::request()->query->all();
$query = $this->request->query->all();
foreach ($types as $pattern_key => $type) {
try {
$pattern = $this->patternStorage->create($type);
......
......@@ -170,12 +170,12 @@ class PatternLibraryJSONForm extends ConfigFormBase {
'#default_value' => $config->get('patternkit_json_editor_disable_edit_json_button') ?? TRUE,
];
$form['patternkit_json_editor_cache_schemas'] = array(
$form['patternkit_json_editor_cache_schemas'] = [
'#type' => 'checkbox',
'#title' => t('Cache external schema references'),
'#description' => t('Select whether JSON Editor should cache schema lookups, which can speed up the editor form (maps to JSON Editor option <em>ajax_cache_responses</em>).'),
'#title' => $this->t('Cache external schema references'),
'#description' => $this->t('Select whether JSON Editor should cache schema lookups, which can speed up the editor form (maps to JSON Editor option <em>ajax_cache_responses</em>).'),
'#default_value' => $config->get('patternkit_json_editor_cache_schemas') ?? FALSE,
);
];
$form['patternkit_json_editor_wysiwyg'] = [
'#type' => 'select',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment