Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
9c74b547
Commit
9c74b547
authored
Apr 18, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1863816
by dawehner, yched, rootatwc: Allow plugins to have services injected.
parent
3e88fc4e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
7 deletions
+96
-7
core/lib/Drupal/Core/Plugin/ContainerFactoryPluginBase.php
core/lib/Drupal/Core/Plugin/ContainerFactoryPluginBase.php
+37
-0
core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php
core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php
+25
-0
core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php
...ules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php
+2
-1
core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php
...odules/views/lib/Drupal/views/Plugin/views/PluginBase.php
+2
-2
core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php
...ews/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php
+2
-2
core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php
...dules/views/lib/Drupal/views/Plugin/views/style/Table.php
+28
-2
No files found.
core/lib/Drupal/Core/Plugin/ContainerFactoryPluginBase.php
0 → 100644
View file @
9c74b547
<?php
/**
* @file
* Contains \Drupal\Core\Plugin\ContainerFactoryPluginBase.
*/
namespace
Drupal\Core\Plugin
;
use
Drupal\Component\Plugin\PluginBase
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Defines a base plugin that can pull it's dependencies from the container.
*/
class
ContainerFactoryPluginBase
extends
PluginBase
{
/**
* Creates an instance of the plugin.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container to pull out services used in the plugin.
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
*
* @return static
* Returns an instance of this plugin.
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
array
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
);
}
}
core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php
0 → 100644
View file @
9c74b547
<?php
/**
* @file
* Contains \Drupal\Core\Plugin\Factory\ContainerFactory.
*/
namespace
Drupal\Core\Plugin\Factory
;
use
Drupal\Component\Plugin\Factory\DefaultFactory
;
/**
* Plugin factory which passes a container to a create method.
*/
class
ContainerFactory
extends
DefaultFactory
{
/**
* {inheritdoc}
*/
public
function
createInstance
(
$plugin_id
,
array
$configuration
)
{
$plugin_definition
=
$this
->
discovery
->
getDefinition
(
$plugin_id
);
$plugin_class
=
static
::
getPluginClass
(
$plugin_id
,
$plugin_definition
);
return
$plugin_class
::
create
(
\
Drupal
::
getContainer
(),
$configuration
,
$plugin_id
,
$plugin_definition
);
}
}
core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php
View file @
9c74b547
...
...
@@ -14,6 +14,7 @@
use
Drupal\Core\Plugin\Discovery\AlterDecorator
;
use
Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery
;
use
Drupal\Core\Plugin\Discovery\CacheDecorator
;
use
Drupal\Core\Plugin\Factory\ContainerFactory
;
/**
* Plugin type manager for all views plugins.
...
...
@@ -35,7 +36,7 @@ public function __construct($type, array $namespaces = array()) {
$this
->
discovery
=
new
AlterDecorator
(
$this
->
discovery
,
'views_plugins_'
.
$type
);
$this
->
discovery
=
new
CacheDecorator
(
$this
->
discovery
,
'views:'
.
$type
,
'views_info'
);
$this
->
factory
=
new
Default
Factory
(
$this
->
discovery
);
$this
->
factory
=
new
Container
Factory
(
$this
);
$this
->
defaults
+=
array
(
'parent'
=>
'parent'
,
...
...
core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php
View file @
9c74b547
...
...
@@ -7,11 +7,11 @@
namespace
Drupal\views\Plugin\views
;
use
Drupal\Core\Plugin\ContainerFactoryPluginBase
;
use
Drupal\views\Plugin\views\display\DisplayPluginBase
;
use
Drupal\Component\Plugin\PluginBase
as
ComponentPluginBase
;
use
Drupal\views\ViewExecutable
;
abstract
class
PluginBase
extends
Co
mponent
PluginBase
{
abstract
class
PluginBase
extends
Co
ntainerFactory
PluginBase
{
/**
* Options for this plugin will be held here.
...
...
core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php
View file @
9c74b547
...
...
@@ -6,7 +6,7 @@
*/
namespace
Drupal\views\Plugin\views\join
;
use
Drupal\Co
mponent
\Plugin\PluginBase
;
use
Drupal\Co
re
\Plugin\
ContainerFactory
PluginBase
;
/**
* @defgroup views_join_handlers Views join handlers
...
...
@@ -49,7 +49,7 @@
*
* Extensions of this class can be used to create more interesting joins.
*/
class
JoinPluginBase
extends
PluginBase
{
class
JoinPluginBase
extends
ContainerFactory
PluginBase
{
/**
* The table to join (right table).
...
...
core/modules/views/lib/Drupal/views/Plugin/views/style/Table.php
View file @
9c74b547
...
...
@@ -7,9 +7,12 @@
namespace
Drupal\views\Plugin\views\style
;
use
Drupal\Component\Plugin\Discovery\DiscoveryInterface
;
use
Drupal\views\Plugin\views\wizard\WizardInterface
;
use
Drupal\Component\Annotation\Plugin
;
use
Drupal\Core\Annotation\Translation
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* Style plugin to render each item as a row in a table.
...
...
@@ -59,6 +62,29 @@ class Table extends StylePluginBase {
*/
public
$order
;
/**
* Contains the current request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected
$request
;
/**
* {inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
array
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'request'
));
}
/**
* Constructs a Table object.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
array
$plugin_definition
,
Request
$request
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
request
=
$request
;
}
protected
function
defineOptions
()
{
$options
=
parent
::
defineOptions
();
...
...
@@ -80,7 +106,7 @@ protected function defineOptions() {
* @return bool
*/
function
build_sort
()
{
$order
=
drupal_container
()
->
get
(
'
request
'
)
->
query
->
get
(
'order'
);
$order
=
$this
->
request
->
query
->
get
(
'order'
);
if
(
!
isset
(
$order
)
&&
(
$this
->
options
[
'default'
]
==
-
1
||
empty
(
$this
->
view
->
field
[
$this
->
options
[
'default'
]])))
{
return
TRUE
;
}
...
...
@@ -98,7 +124,7 @@ function build_sort() {
* Add our actual sort criteria
*/
function
build_sort_post
()
{
$query
=
drupal_container
()
->
get
(
'
request
'
)
->
query
;
$query
=
$this
->
request
->
query
;
$order
=
$query
->
get
(
'order'
);
if
(
!
isset
(
$order
))
{
// check for a 'default' clicksort. If there isn't one, exit gracefully.
...
...
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