Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
229
Merge Requests
229
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
0613dbf5
Commit
0613dbf5
authored
Mar 20, 2018
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2949965
by alexpott, Lendude: \Drupal::classResolver() could be more helpful
parent
0a97488e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
13 deletions
+34
-13
core/lib/Drupal.php
core/lib/Drupal.php
+13
-3
core/modules/field_layout/field_layout.module
core/modules/field_layout/field_layout.module
+2
-4
core/modules/inline_form_errors/inline_form_errors.module
core/modules/inline_form_errors/inline_form_errors.module
+1
-2
core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.install
...ami/modules/demo_umami_content/demo_umami_content.install
+2
-2
core/tests/Drupal/Tests/Core/DrupalTest.php
core/tests/Drupal/Tests/Core/DrupalTest.php
+16
-2
No files found.
core/lib/Drupal.php
View file @
0613dbf5
...
...
@@ -320,10 +320,20 @@ public static function cache($bin = 'default') {
* One common usecase is to provide a class which contains the actual code
* of a hook implementation, without having to create a service.
*
* @return \Drupal\Core\DependencyInjection\ClassResolverInterface
* The class resolver.
* @param string $class
* (optional) A class name to instantiate.
*
* @return \Drupal\Core\DependencyInjection\ClassResolverInterface|object
* The class resolver or if $class is provided, a class instance with a
* given class definition.
*
* @throws \InvalidArgumentException
* If $class does not exist.
*/
public
static
function
classResolver
()
{
public
static
function
classResolver
(
$class
=
NULL
)
{
if
(
$class
)
{
return
static
::
getContainer
()
->
get
(
'class_resolver'
)
->
getInstanceFromDefinition
(
$class
);
}
return
static
::
getContainer
()
->
get
(
'class_resolver'
);
}
...
...
core/modules/field_layout/field_layout.module
View file @
0613dbf5
...
...
@@ -50,8 +50,7 @@ function field_layout_entity_type_alter(array &$entity_types) {
*/
function
field_layout_entity_view_alter
(
array
&
$build
,
EntityInterface
$entity
,
EntityViewDisplayInterface
$display
)
{
if
(
$display
instanceof
EntityDisplayWithLayoutInterface
)
{
\
Drupal
::
classResolver
()
->
getInstanceFromDefinition
(
FieldLayoutBuilder
::
class
)
->
buildView
(
$build
,
$display
);
\
Drupal
::
classResolver
(
FieldLayoutBuilder
::
class
)
->
buildView
(
$build
,
$display
);
}
}
...
...
@@ -62,8 +61,7 @@ function field_layout_form_alter(&$form, FormStateInterface $form_state, $form_i
$form_object
=
$form_state
->
getFormObject
();
if
(
$form_object
instanceof
ContentEntityFormInterface
&&
$display
=
$form_object
->
getFormDisplay
(
$form_state
))
{
if
(
$display
instanceof
EntityDisplayWithLayoutInterface
)
{
\
Drupal
::
classResolver
()
->
getInstanceFromDefinition
(
FieldLayoutBuilder
::
class
)
->
buildForm
(
$form
,
$display
);
\
Drupal
::
classResolver
(
FieldLayoutBuilder
::
class
)
->
buildForm
(
$form
,
$display
);
}
}
}
core/modules/inline_form_errors/inline_form_errors.module
View file @
0613dbf5
...
...
@@ -59,8 +59,7 @@ function inline_form_errors_preprocess_datetime_wrapper(&$variables) {
* Implements hook_element_info_alter().
*/
function
inline_form_errors_element_info_alter
(
array
&
$info
)
{
\
Drupal
::
classResolver
()
->
getInstanceFromDefinition
(
RenderElementHelper
::
class
)
->
alterElementInfo
(
$info
);
\
Drupal
::
classResolver
(
RenderElementHelper
::
class
)
->
alterElementInfo
(
$info
);
}
/**
...
...
core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.install
View file @
0613dbf5
...
...
@@ -12,7 +12,7 @@
*/
function
demo_umami_content_install
()
{
if
(
!
\
Drupal
::
service
(
'config.installer'
)
->
isSyncing
())
{
\
Drupal
::
classResolver
(
)
->
getInstanceFromDefinition
(
InstallHelper
::
class
)
->
importContent
();
\
Drupal
::
classResolver
(
InstallHelper
::
class
)
->
importContent
();
}
}
...
...
@@ -21,6 +21,6 @@ function demo_umami_content_install() {
*/
function
demo_umami_content_uninstall
()
{
if
(
!
\
Drupal
::
service
(
'config.installer'
)
->
isSyncing
())
{
\
Drupal
::
classResolver
(
)
->
getInstanceFromDefinition
(
InstallHelper
::
class
)
->
deleteImportedContent
();
\
Drupal
::
classResolver
(
InstallHelper
::
class
)
->
deleteImportedContent
();
}
}
core/tests/Drupal/Tests/Core/DrupalTest.php
View file @
0613dbf5
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\Tests\Core
;
use
Drupal\Core\DependencyInjection\ClassResolverInterface
;
use
Drupal\Core\DependencyInjection\ContainerNotInitializedException
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
...
...
@@ -120,8 +121,21 @@ public function testCache() {
* @covers ::classResolver
*/
public
function
testClassResolver
()
{
$this
->
setMockContainerService
(
'class_resolver'
);
$this
->
assertNotNull
(
\
Drupal
::
classResolver
());
$class_resolver
=
$this
->
prophesize
(
ClassResolverInterface
::
class
);
$this
->
setMockContainerService
(
'class_resolver'
,
$class_resolver
->
reveal
());
$this
->
assertInstanceOf
(
ClassResolverInterface
::
class
,
\
Drupal
::
classResolver
());
}
/**
* Tests the classResolver method when called with a class.
*
* @covers ::classResolver
*/
public
function
testClassResolverWithClass
()
{
$class_resolver
=
$this
->
prophesize
(
ClassResolverInterface
::
class
);
$class_resolver
->
getInstanceFromDefinition
(
static
::
class
)
->
willReturn
(
$this
);
$this
->
setMockContainerService
(
'class_resolver'
,
$class_resolver
->
reveal
());
$this
->
assertSame
(
$this
,
\
Drupal
::
classResolver
(
static
::
class
));
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment