Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Data Class Reference
Inheritance diagram for Data:
AbstractHelper Data

Public Member Functions

 __construct (Context $context, StringUtils $string, Escaper $escaper, StoreManagerInterface $storeManager)
 
 isMinQueryLength ()
 
 getEscapedQueryText ()
 
 getResultUrl ($query=null)
 
 getSuggestUrl ()
 
 getSearchTermUrl ()
 
 getMinQueryLength ($store=null)
 
 getMaxQueryLength ($store=null)
 
 addNoteMessage ($message)
 
 setNoteMessages (array $messages)
 
 getNoteMessages ()
 
 checkNotes ($store=null)
 
 getQueryParamName ()
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Protected Attributes

 $_messages = []
 
 $string
 
 $scopeConfig
 
 $escaper
 
 $storeManager
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

Search helper @api

Since
100.0.2

Definition at line 22 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Context  $context,
StringUtils  $string,
Escaper  $escaper,
StoreManagerInterface  $storeManager 
)

Construct

Parameters
Context$context
StringUtils$string
Escaper$escaper
StoreManagerInterface$storeManager

Definition at line 66 of file Data.php.

71  {
72  $this->string = $string;
73  $this->scopeConfig = $context->getScopeConfig();
74  $this->escaper = $escaper;
75  $this->storeManager = $storeManager;
76  parent::__construct($context);
77  }

Member Function Documentation

◆ addNoteMessage()

addNoteMessage (   $message)

Add Note message

Parameters
string$message
Returns
$this

Definition at line 177 of file Data.php.

178  {
179  $this->_messages[] = $message;
180  return $this;
181  }
$message

◆ checkNotes()

checkNotes (   $store = null)

Check query of a warnings

Parameters
mixed$store
Returns
$this @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 212 of file Data.php.

213  {
214  if ($this->isQueryTooLong($this->getQueryText(), $this->getMaxQueryLength())) {
215  $this->addNoteMessage(
216  __(
217  'Your search query can\'t be longer than %1, so we shortened your query.',
218  $this->getMaxQueryLength()
219  )
220  );
221  }
222 
223  return $this;
224  }
__()
Definition: __.php:13
addNoteMessage($message)
Definition: Data.php:177
getMaxQueryLength($store=null)
Definition: Data.php:162

◆ getEscapedQueryText()

getEscapedQueryText ( )

Retrieve HTML escaped search query

Returns
string

Definition at line 96 of file Data.php.

97  {
98  return $this->escaper->escapeHtml(
99  $this->getPreparedQueryText($this->getQueryText(), $this->getMaxQueryLength())
100  );
101  }
getMaxQueryLength($store=null)
Definition: Data.php:162

◆ getMaxQueryLength()

getMaxQueryLength (   $store = null)

Retrieve maximum query length

Parameters
mixed$store
Returns
int|string

Definition at line 162 of file Data.php.

163  {
164  return $this->scopeConfig->getValue(
165  SearchQuery::XML_PATH_MAX_QUERY_LENGTH,
166  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
167  $store
168  );
169  }

◆ getMinQueryLength()

getMinQueryLength (   $store = null)

Retrieve minimum query length

Parameters
mixed$store
Returns
int|string

Definition at line 147 of file Data.php.

148  {
149  return $this->scopeConfig->getValue(
150  SearchQuery::XML_PATH_MIN_QUERY_LENGTH,
151  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
152  $store
153  );
154  }

◆ getNoteMessages()

getNoteMessages ( )

Retrieve Current Note messages

Returns
array

Definition at line 200 of file Data.php.

201  {
202  return $this->_messages;
203  }

◆ getQueryParamName()

getQueryParamName ( )
Returns
string

Definition at line 229 of file Data.php.

230  {
232  }

◆ getResultUrl()

getResultUrl (   $query = null)

Retrieve result page url and set "secure" param to avoid confirm message when we submit form from secure page to unsecure

Parameters
string$query
Returns
string

Definition at line 110 of file Data.php.

111  {
112  return $this->_getUrl(
113  'catalogsearch/result',
114  ['_query' => [QueryFactory::QUERY_VAR_NAME => $query], '_secure' => $this->_request->isSecure()]
115  );
116  }

◆ getSearchTermUrl()

getSearchTermUrl ( )

Retrieve search term url

Returns
string

Definition at line 136 of file Data.php.

137  {
138  return $this->_getUrl('search/term/popular');
139  }

◆ getSuggestUrl()

getSuggestUrl ( )

Retrieve suggest url

Returns
string

Definition at line 123 of file Data.php.

124  {
125  return $this->_getUrl(
126  'search/ajax/suggest',
127  ['_secure' => $this->_getRequest()->isSecure()]
128  );
129  }

◆ isMinQueryLength()

isMinQueryLength ( )

Is a minimum query length

Returns
bool

Definition at line 84 of file Data.php.

85  {
86  $minQueryLength = $this->getMinQueryLength();
87  $thisQueryLength = $this->string->strlen($this->getQueryText());
88  return !$thisQueryLength || $minQueryLength !== '' && $thisQueryLength < $minQueryLength;
89  }
getMinQueryLength($store=null)
Definition: Data.php:147

◆ setNoteMessages()

setNoteMessages ( array  $messages)

Set Note messages

Parameters
array$messages
Returns
$this

Definition at line 189 of file Data.php.

190  {
191  $this->_messages = $messages;
192  return $this;
193  }

Field Documentation

◆ $_messages

$_messages = []
protected

Definition at line 29 of file Data.php.

◆ $escaper

$escaper
protected

Definition at line 50 of file Data.php.

◆ $scopeConfig

$scopeConfig
protected

Definition at line 44 of file Data.php.

◆ $storeManager

$storeManager
protected

Definition at line 56 of file Data.php.

◆ $string

$string
protected

Definition at line 36 of file Data.php.


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