Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
Title Class Reference

Public Member Functions

 __construct (App\Config\ScopeConfigInterface $scopeConfig)
 
 set ($title)
 
 get ()
 
 getShort ()
 
 getShortHeading ()
 
 getDefault ()
 
 append ($suffix)
 
 prepend ($prefix)
 
 unsetValue ()
 

Data Fields

const TITLE_GLUE = ' / '
 

Protected Member Functions

 build ($withConfigValues=true)
 
 addConfigValues ($title)
 

Detailed Description

Page title

@api

Since
100.0.2

Definition at line 17 of file Title.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( App\Config\ScopeConfigInterface  $scopeConfig)
Parameters
App\Config\ScopeConfigInterface$scopeConfig

Definition at line 47 of file Title.php.

49  {
50  $this->scopeConfig = $scopeConfig;
51  }

Member Function Documentation

◆ addConfigValues()

addConfigValues (   $title)
protected
Parameters
string$title
Returns
string

Definition at line 113 of file Title.php.

114  {
115  $preparedTitle = $this->scopeConfig->getValue(
116  'design/head/title_prefix',
117  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
118  ) . ' ' . $title . ' ' . $this->scopeConfig->getValue(
119  'design/head/title_suffix',
120  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
121  );
122  return trim($preparedTitle);
123  }
$title
Definition: default.phtml:14

◆ append()

append (   $suffix)
Parameters
string$suffix
Returns
void

Definition at line 143 of file Title.php.

144  {
145  $this->appendedValues[] = $suffix;
146  }
$suffix
Definition: name.phtml:27

◆ build()

build (   $withConfigValues = true)
protected
Parameters
bool$withConfigValues
Returns
array

Definition at line 100 of file Title.php.

101  {
102  return array_merge(
103  $this->prependedValues,
104  [$withConfigValues ? $this->addConfigValues($this->textValue) : $this->textValue],
105  $this->appendedValues
106  );
107  }

◆ get()

get ( )

Retrieve title element text (encoded)

Returns
string

Definition at line 70 of file Title.php.

71  {
72  return join(self::TITLE_GLUE, $this->build());
73  }
build($withConfigValues=true)
Definition: Title.php:100

◆ getDefault()

getDefault ( )

Retrieve default title text

Returns
string

Definition at line 130 of file Title.php.

131  {
132  $defaultTitle = $this->scopeConfig->getValue(
133  'design/head/default_title',
134  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
135  );
136  return $this->addConfigValues($defaultTitle);
137  }

◆ getShort()

getShort ( )

Same as getTitle(), but return only first item from chunk

Returns
mixed

Definition at line 80 of file Title.php.

81  {
82  $title = $this->build();
83  return reset($title);
84  }
$title
Definition: default.phtml:14
build($withConfigValues=true)
Definition: Title.php:100

◆ getShortHeading()

getShortHeading ( )

Same as getShort(), but return title without prefix and suffix

Returns
mixed

Definition at line 90 of file Title.php.

91  {
92  $title = $this->build(false);
93  return reset($title);
94  }
$title
Definition: default.phtml:14
build($withConfigValues=true)
Definition: Title.php:100

◆ prepend()

prepend (   $prefix)
Parameters
string$prefix
Returns
void

Definition at line 152 of file Title.php.

153  {
154  array_unshift($this->prependedValues, $prefix);
155  }
$prefix
Definition: name.phtml:25

◆ set()

set (   $title)

Set page title

Parameters
string$title
Returns
$this

Definition at line 59 of file Title.php.

60  {
61  $this->textValue = $title;
62  return $this;
63  }
$title
Definition: default.phtml:14

◆ unsetValue()

unsetValue ( )

Unset title

Returns
void

Definition at line 162 of file Title.php.

163  {
164  $this->textValue = null;
165  }

Field Documentation

◆ TITLE_GLUE

const TITLE_GLUE = ' / '

Default title glue

Definition at line 22 of file Title.php.


The documentation for this class was generated from the following file: