7
7
namespace Magento \Framework \View \Page ;
8
8
9
9
use Magento \Framework \App ;
10
+ use Magento \Framework \App \Area ;
10
11
use Magento \Framework \View ;
11
12
12
13
/**
@@ -34,6 +35,15 @@ class Config
34
35
const ELEMENT_TYPE_HEAD = 'head ' ;
35
36
/**#@-*/
36
37
38
+ const META_DESCRIPTION = 'description ' ;
39
+ const META_CONTENT_TYPE = 'content_type ' ;
40
+ const META_MEDIA_TYPE = 'media_type ' ;
41
+ const META_CHARSET = 'charset ' ;
42
+ const META_TITLE = 'title ' ;
43
+ const META_KEYWORDS = 'keywords ' ;
44
+ const META_ROBOTS = 'robots ' ;
45
+ const META_X_UI_COMPATIBLE = 'x_ua_compatible ' ;
46
+
37
47
/**
38
48
* Constant body attribute class
39
49
*/
@@ -244,7 +254,7 @@ public function getMetadata()
244
254
*/
245
255
public function setContentType ($ contentType )
246
256
{
247
- $ this ->setMetadata (' content_type ' , $ contentType );
257
+ $ this ->setMetadata (self :: META_CONTENT_TYPE , $ contentType );
248
258
}
249
259
250
260
/**
@@ -255,10 +265,10 @@ public function setContentType($contentType)
255
265
public function getContentType ()
256
266
{
257
267
$ this ->build ();
258
- if (strtolower ($ this ->metadata [' content_type ' ]) === 'auto ' ) {
259
- $ this ->metadata [' content_type ' ] = $ this ->getMediaType () . '; charset= ' . $ this ->getCharset ();
268
+ if (strtolower ($ this ->metadata [self :: META_CONTENT_TYPE ]) === 'auto ' ) {
269
+ $ this ->metadata [self :: META_CONTENT_TYPE ] = $ this ->getMediaType () . '; charset= ' . $ this ->getCharset ();
260
270
}
261
- return $ this ->metadata [' content_type ' ];
271
+ return $ this ->metadata [self :: META_CONTENT_TYPE ];
262
272
}
263
273
264
274
/**
@@ -267,7 +277,7 @@ public function getContentType()
267
277
*/
268
278
public function setMediaType ($ mediaType )
269
279
{
270
- $ this ->setMetadata (' media_type ' , $ mediaType );
280
+ $ this ->setMetadata (self :: META_MEDIA_TYPE , $ mediaType );
271
281
}
272
282
273
283
/**
@@ -278,13 +288,13 @@ public function setMediaType($mediaType)
278
288
public function getMediaType ()
279
289
{
280
290
$ this ->build ();
281
- if (empty ($ this ->metadata [' media_type ' ])) {
282
- $ this ->metadata [' media_type ' ] = $ this ->scopeConfig ->getValue (
291
+ if (empty ($ this ->metadata [self :: META_MEDIA_TYPE ])) {
292
+ $ this ->metadata [self :: META_MEDIA_TYPE ] = $ this ->scopeConfig ->getValue (
283
293
'design/head/default_media_type ' ,
284
294
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
285
295
);
286
296
}
287
- return $ this ->metadata [' media_type ' ];
297
+ return $ this ->metadata [self :: META_MEDIA_TYPE ];
288
298
}
289
299
290
300
/**
@@ -293,7 +303,7 @@ public function getMediaType()
293
303
*/
294
304
public function setCharset ($ charset )
295
305
{
296
- $ this ->setMetadata (' charset ' , $ charset );
306
+ $ this ->setMetadata (self :: META_CHARSET , $ charset );
297
307
}
298
308
299
309
/**
@@ -304,13 +314,13 @@ public function setCharset($charset)
304
314
public function getCharset ()
305
315
{
306
316
$ this ->build ();
307
- if (empty ($ this ->metadata [' charset ' ])) {
308
- $ this ->metadata [' charset ' ] = $ this ->scopeConfig ->getValue (
317
+ if (empty ($ this ->metadata [self :: META_CHARSET ])) {
318
+ $ this ->metadata [self :: META_CHARSET ] = $ this ->scopeConfig ->getValue (
309
319
'design/head/default_charset ' ,
310
320
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
311
321
);
312
322
}
313
- return $ this ->metadata [' charset ' ];
323
+ return $ this ->metadata [self :: META_CHARSET ];
314
324
}
315
325
316
326
/**
@@ -319,7 +329,7 @@ public function getCharset()
319
329
*/
320
330
public function setDescription ($ description )
321
331
{
322
- $ this ->setMetadata (' description ' , $ description );
332
+ $ this ->setMetadata (self :: META_DESCRIPTION , $ description );
323
333
}
324
334
325
335
/**
@@ -330,13 +340,36 @@ public function setDescription($description)
330
340
public function getDescription ()
331
341
{
332
342
$ this ->build ();
333
- if (empty ($ this ->metadata [' description ' ])) {
334
- $ this ->metadata [' description ' ] = $ this ->scopeConfig ->getValue (
343
+ if (empty ($ this ->metadata [self :: META_DESCRIPTION ])) {
344
+ $ this ->metadata [self :: META_DESCRIPTION ] = $ this ->scopeConfig ->getValue (
335
345
'design/head/default_description ' ,
336
346
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
337
347
);
338
348
}
339
- return $ this ->metadata ['description ' ];
349
+ return $ this ->metadata [self ::META_DESCRIPTION ];
350
+ }
351
+
352
+ /**
353
+ * @param string $title
354
+ */
355
+ public function setMetaTitle ($ title )
356
+ {
357
+ $ this ->setMetadata (self ::META_TITLE , $ title );
358
+ }
359
+
360
+ /**
361
+ * Retrieve meta title
362
+ *
363
+ * @return string
364
+ */
365
+ public function getMetaTitle ()
366
+ {
367
+ $ this ->build ();
368
+ if (empty ($ this ->metadata [self ::META_TITLE ])) {
369
+ return '' ;
370
+ }
371
+
372
+ return $ this ->metadata [self ::META_TITLE ];
340
373
}
341
374
342
375
/**
@@ -345,7 +378,7 @@ public function getDescription()
345
378
*/
346
379
public function setKeywords ($ keywords )
347
380
{
348
- $ this ->setMetadata (' keywords ' , $ keywords );
381
+ $ this ->setMetadata (self :: META_KEYWORDS , $ keywords );
349
382
}
350
383
351
384
/**
@@ -356,13 +389,13 @@ public function setKeywords($keywords)
356
389
public function getKeywords ()
357
390
{
358
391
$ this ->build ();
359
- if (empty ($ this ->metadata [' keywords ' ])) {
360
- $ this ->metadata [' keywords ' ] = $ this ->scopeConfig ->getValue (
392
+ if (empty ($ this ->metadata [self :: META_KEYWORDS ])) {
393
+ $ this ->metadata [self :: META_KEYWORDS ] = $ this ->scopeConfig ->getValue (
361
394
'design/head/default_keywords ' ,
362
395
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
363
396
);
364
397
}
365
- return $ this ->metadata [' keywords ' ];
398
+ return $ this ->metadata [self :: META_KEYWORDS ];
366
399
}
367
400
368
401
/**
@@ -371,27 +404,28 @@ public function getKeywords()
371
404
*/
372
405
public function setRobots ($ robots )
373
406
{
374
- $ this ->setMetadata (' robots ' , $ robots );
407
+ $ this ->setMetadata (self :: META_ROBOTS , $ robots );
375
408
}
376
409
377
410
/**
378
411
* Retrieve URL to robots file
379
412
*
380
413
* @return string
414
+ * @throws \Magento\Framework\Exception\LocalizedException
381
415
*/
382
416
public function getRobots ()
383
417
{
384
- if ($ this ->getAreaResolver ()->getAreaCode () !== ' frontend ' ) {
418
+ if ($ this ->getAreaResolver ()->getAreaCode () !== Area:: AREA_FRONTEND ) {
385
419
return 'NOINDEX,NOFOLLOW ' ;
386
420
}
387
421
$ this ->build ();
388
- if (empty ($ this ->metadata [' robots ' ])) {
389
- $ this ->metadata [' robots ' ] = $ this ->scopeConfig ->getValue (
422
+ if (empty ($ this ->metadata [self :: META_ROBOTS ])) {
423
+ $ this ->metadata [self :: META_ROBOTS ] = $ this ->scopeConfig ->getValue (
390
424
'design/search_engine_robots/default_robots ' ,
391
425
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
392
426
);
393
427
}
394
- return $ this ->metadata [' robots ' ];
428
+ return $ this ->metadata [self :: META_ROBOTS ];
395
429
}
396
430
397
431
/**
0 commit comments