5
5
use Drupal \Component \Datetime \TimeInterface ;
6
6
use Drupal \Core \Block \BlockBase ;
7
7
use Drupal \Core \Datetime \DateFormatter ;
8
- use Drupal \Core \Datetime \Entity \DateFormat ;
9
8
use Drupal \Core \Entity \EntityStorageInterface ;
10
9
use Drupal \Core \Form \FormStateInterface ;
11
10
use Drupal \Core \Plugin \ContainerFactoryPluginInterface ;
@@ -30,6 +29,13 @@ class DateModifiedBlock extends BlockBase implements ContainerFactoryPluginInter
30
29
*/
31
30
protected $ requestStack ;
32
31
32
+ /**
33
+ * The date format storage.
34
+ *
35
+ * @var \Drupal\Core\Entity\EntityStorageInterface
36
+ */
37
+ protected $ dateFormatStorage ;
38
+
33
39
/**
34
40
* The node storage.
35
41
*
@@ -60,6 +66,8 @@ class DateModifiedBlock extends BlockBase implements ContainerFactoryPluginInter
60
66
* The plugin_id for the plugin instance.
61
67
* @param string $plugin_definition
62
68
* The plugin implementation definition.
69
+ * @param \Drupal\Core\Entity\EntityStorageInterface $date_format_storage
70
+ * Entity storage for date_format entities.
63
71
* @param \Drupal\Core\Datetime\DateFormatter $date_formatter
64
72
* The date formatter service.
65
73
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
@@ -73,12 +81,14 @@ public function __construct(
73
81
array $ configuration ,
74
82
$ plugin_id ,
75
83
$ plugin_definition ,
84
+ EntityStorageInterface $ date_format_storage ,
76
85
DateFormatter $ date_formatter ,
77
86
RequestStack $ request_stack ,
78
87
EntityStorageInterface $ node_storage ,
79
88
TimeInterface $ date_time
80
89
) {
81
90
parent ::__construct ($ configuration , $ plugin_id , $ plugin_definition );
91
+ $ this ->dateFormatStorage = $ date_format_storage ;
82
92
$ this ->dateFormatter = $ date_formatter ;
83
93
$ this ->requestStack = $ request_stack ;
84
94
$ this ->nodeStorage = $ node_storage ;
@@ -93,6 +103,7 @@ public static function create(ContainerInterface $container, array $configuratio
93
103
$ configuration ,
94
104
$ plugin_id ,
95
105
$ plugin_definition ,
106
+ $ container ->get ('entity_type.manager ' )->getStorage ('date_format ' ),
96
107
$ container ->get ('date.formatter ' ),
97
108
$ container ->get ('request_stack ' ),
98
109
$ container ->get ('entity_type.manager ' )->getStorage ('node ' ),
@@ -162,7 +173,7 @@ public function build() {
162
173
$ formatted_date = 'Y-m-d ' ;
163
174
}
164
175
else {
165
- $ formatted_date = DateFormat:: load ($ format )->getPattern ();
176
+ $ formatted_date = $ this -> dateFormatStorage -> load ($ format )->getPattern ();
166
177
}
167
178
$ date = $ this ->dateFormatter ->format ($ time , 'custom ' , $ formatted_date );
168
179
0 commit comments