Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds-3306211
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
feeds-3306211
Commits
72c28fd6
Commit
72c28fd6
authored
6 years ago
by
Thalles Ferreira
Committed by
Youri van Koppen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3021251
by thalles, MegaChriz: Fixed use dependency injection in FeedTypeForm.
parent
41ee9e70
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/FeedTypeForm.php
+30
-7
30 additions, 7 deletions
src/FeedTypeForm.php
with
30 additions
and
7 deletions
src/FeedTypeForm.php
+
30
−
7
View file @
72c28fd6
...
...
@@ -7,10 +7,12 @@ use Drupal\Core\Ajax\AjaxResponse;
use
Drupal\Core\Ajax\HtmlCommand
;
use
Drupal\Core\Ajax\ReplaceCommand
;
use
Drupal\Core\Config\Entity\ConfigEntityStorageInterface
;
use
Drupal\Core\Datetime\DateFormatterInterface
;
use
Drupal\Core\Entity\EntityForm
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Form\FormState
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Render\RendererInterface
;
use
Drupal\feeds\Ajax\SetHashCommand
;
use
Drupal\feeds\Plugin\PluginFormFactory
;
use
Drupal\feeds\Plugin\Type\FeedsPluginInterface
;
...
...
@@ -36,6 +38,20 @@ class FeedTypeForm extends EntityForm {
*/
protected
$formFactory
;
/**
* Provides a service to handle various date related functionality.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected
$dateFormatter
;
/**
* Turns a render array into a HTML string.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected
$renderer
;
/**
* Constructs a new FeedTypeForm object.
*
...
...
@@ -43,10 +59,16 @@ class FeedTypeForm extends EntityForm {
* The feed type storage controller.
* @param \Drupal\feeds\Plugin\PluginFormFactory $factory
* The form factory.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The services of date.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The render object.
*/
public
function
__construct
(
ConfigEntityStorageInterface
$feed_type_storage
,
PluginFormFactory
$factory
)
{
public
function
__construct
(
ConfigEntityStorageInterface
$feed_type_storage
,
PluginFormFactory
$factory
,
DateFormatterInterface
$date_formatter
,
RendererInterface
$renderer
)
{
$this
->
feedTypeStorage
=
$feed_type_storage
;
$this
->
formFactory
=
$factory
;
$this
->
dateFormatter
=
$date_formatter
;
$this
->
renderer
=
$renderer
;
}
/**
...
...
@@ -55,7 +77,9 @@ class FeedTypeForm extends EntityForm {
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
)
->
getStorage
(
'feeds_feed_type'
),
$container
->
get
(
'feeds_plugin_form_factory'
)
$container
->
get
(
'feeds_plugin_form_factory'
),
$container
->
get
(
'date.formatter'
),
$container
->
get
(
'renderer'
)
);
}
...
...
@@ -133,7 +157,7 @@ class FeedTypeForm extends EntityForm {
];
$period
=
array_map
(
function
(
$time
)
{
return
\Drupal
::
service
(
'
date
.f
ormatter
'
)
->
formatInterval
(
$time
);
return
$this
->
date
F
ormatter
->
formatInterval
(
$time
);
},
array_combine
(
$times
,
$times
));
foreach
(
$period
as
&
$p
)
{
...
...
@@ -327,7 +351,6 @@ class FeedTypeForm extends EntityForm {
* Sends an ajax response.
*/
public
function
ajaxCallback
(
array
$form
,
FormStateInterface
$form_state
)
{
$renderer
=
\Drupal
::
service
(
'renderer'
);
$type
=
$form_state
->
getTriggeringElement
()[
'#plugin_type'
];
$response
=
new
AjaxResponse
();
...
...
@@ -339,8 +362,8 @@ class FeedTypeForm extends EntityForm {
}
// Update the forms.
$plugin_settings
=
$renderer
->
renderRoot
(
$form
[
'plugin_settings'
]);
$advanced_settings
=
$renderer
->
renderRoot
(
$form
[
$type
.
'_wrapper'
][
'advanced'
]);
$plugin_settings
=
$
this
->
renderer
->
renderRoot
(
$form
[
'plugin_settings'
]);
$advanced_settings
=
$
this
->
renderer
->
renderRoot
(
$form
[
$type
.
'_wrapper'
][
'advanced'
]);
$response
->
addCommand
(
new
ReplaceCommand
(
'#feeds-ajax-form-wrapper'
,
$plugin_settings
));
$response
->
addCommand
(
new
ReplaceCommand
(
'#feeds-plugin-'
.
$type
.
'-advanced'
,
$advanced_settings
));
...
...
@@ -350,7 +373,7 @@ class FeedTypeForm extends EntityForm {
// Display status messages.
$status_messages
=
[
'#type'
=>
'status_messages'
];
$output
=
$renderer
->
renderRoot
(
$status_messages
);
$output
=
$
this
->
renderer
->
renderRoot
(
$status_messages
);
if
(
!
empty
(
$output
))
{
$response
->
addCommand
(
new
HtmlCommand
(
'.region-messages'
,
$output
));
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment