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

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, Filesystem $filesystem, \Magento\Captcha\Model\CaptchaFactory $factory)
 
 getCaptcha ($formId)
 
 getConfig ($key, $store=null)
 
 getFonts ()
 
 getImgDir ($website=null)
 
 getImgUrl ($website=null)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const INPUT_NAME_FIELD_VALUE = 'captcha'
 
const MODE_ALWAYS = 'always'
 
const MODE_AFTER_FAIL = 'after_fail'
 
const XML_PATH_CAPTCHA_FONTS = 'captcha/fonts'
 
const DEFAULT_CAPTCHA_TYPE = 'Zend'
 

Protected Member Functions

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

Protected Attributes

 $_captcha = []
 
 $_filesystem
 
 $_storeManager
 
 $_factory
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Detailed Description

Captcha image model

@api

Since
100.0.2

Definition at line 18 of file Data.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Store\Model\StoreManagerInterface$storeManager
Filesystem$filesystem
\Magento\Captcha\Model\CaptchaFactory$factory

Definition at line 72 of file Data.php.

77  {
78  $this->_storeManager = $storeManager;
79  $this->_filesystem = $filesystem;
80  $this->_factory = $factory;
81  parent::__construct($context);
82  }
$storeManager
$filesystem

Member Function Documentation

◆ _getWebsiteCode()

_getWebsiteCode (   $website = null)
protected

Get website code

Parameters
mixed$website
Returns
string

Definition at line 165 of file Data.php.

166  {
167  return $this->_storeManager->getWebsite($website)->getCode();
168  }

◆ getCaptcha()

getCaptcha (   $formId)

Get Captcha

Parameters
string$formId
Returns
\Magento\Captcha\Model\CaptchaInterface

Definition at line 90 of file Data.php.

91  {
92  if (!array_key_exists($formId, $this->_captcha)) {
93  $captchaType = ucfirst($this->getConfig('type'));
94  if (!$captchaType) {
95  $captchaType = self::DEFAULT_CAPTCHA_TYPE;
96  } elseif ($captchaType == 'Default') {
97  $captchaType = $captchaType . 'Model';
98  }
99 
100  $this->_captcha[$formId] = $this->_factory->create($captchaType, $formId);
101  }
102  return $this->_captcha[$formId];
103  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getConfig($key, $store=null)
Definition: Data.php:112

◆ getConfig()

getConfig (   $key,
  $store = null 
)

Returns config value

Parameters
string$keyThe last part of XML_PATH_$area_CAPTCHA_ constant (case insensitive)
\Magento\Store\Model\Store$store
Returns
\Magento\Framework\App\Config\Element

Definition at line 112 of file Data.php.

113  {
114  return $this->scopeConfig->getValue(
115  'customer/captcha/' . $key,
116  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
117  $store
118  );
119  }

◆ getFonts()

getFonts ( )

Get list of available fonts.

Return format: [['arial'] => ['label' => 'Arial', 'path' => '/www/magento/fonts/arial.ttf']]

Returns
array

Definition at line 129 of file Data.php.

130  {
131  $fontsConfig = $this->scopeConfig->getValue(\Magento\Captcha\Helper\Data::XML_PATH_CAPTCHA_FONTS, 'default');
132  $fonts = [];
133  if ($fontsConfig) {
134  $libDir = $this->_filesystem->getDirectoryRead(DirectoryList::LIB_INTERNAL);
135  foreach ($fontsConfig as $fontName => $fontConfig) {
136  $fonts[$fontName] = [
137  'label' => $fontConfig['label'],
138  'path' => $libDir->getAbsolutePath($fontConfig['path']),
139  ];
140  }
141  }
142  return $fonts;
143  }

◆ getImgDir()

getImgDir (   $website = null)

Get captcha image directory

Parameters
mixed$website
Returns
string

Definition at line 151 of file Data.php.

152  {
153  $mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
154  $captchaDir = '/captcha/' . $this->_getWebsiteCode($website);
155  $mediaDir->create($captchaDir);
156  return $mediaDir->getAbsolutePath($captchaDir) . '/';
157  }
_getWebsiteCode($website=null)
Definition: Data.php:165

◆ getImgUrl()

getImgUrl (   $website = null)

Get captcha image base URL

Parameters
mixed$website
Returns
string

Definition at line 176 of file Data.php.

177  {
178  return $this->_storeManager->getStore()->getBaseUrl(
180  ) . 'captcha' . '/' . $this->_getWebsiteCode(
181  $website
182  ) . '/';
183  }
_getWebsiteCode($website=null)
Definition: Data.php:165

Field Documentation

◆ $_captcha

$_captcha = []
protected

Definition at line 49 of file Data.php.

◆ $_factory

$_factory
protected

Definition at line 64 of file Data.php.

◆ $_filesystem

$_filesystem
protected

Definition at line 54 of file Data.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 59 of file Data.php.

◆ DEFAULT_CAPTCHA_TYPE

const DEFAULT_CAPTCHA_TYPE = 'Zend'

Default captcha type

Definition at line 43 of file Data.php.

◆ INPUT_NAME_FIELD_VALUE

const INPUT_NAME_FIELD_VALUE = 'captcha'

Used for "name" attribute of captcha's input field

Definition at line 23 of file Data.php.

◆ MODE_AFTER_FAIL

const MODE_AFTER_FAIL = 'after_fail'

Show captcha only after certain number of unsuccessful attempts

Definition at line 33 of file Data.php.

◆ MODE_ALWAYS

const MODE_ALWAYS = 'always'

Always show captcha

Definition at line 28 of file Data.php.

◆ XML_PATH_CAPTCHA_FONTS

const XML_PATH_CAPTCHA_FONTS = 'captcha/fonts'

Captcha fonts path

Definition at line 38 of file Data.php.


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