Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Name Class Reference
Inheritance diagram for Name:
AbstractWidget Template AbstractBlock DataObject BlockInterface

Public Member Functions

 __construct (Context $context, AddressHelper $addressHelper, CustomerMetadataInterface $customerMetadata, Options $options, AddressMetadataInterface $addressMetadata, array $data=[])
 
 _construct ()
 
 showPrefix ()
 
 isPrefixRequired ()
 
 getPrefixOptions ()
 
 showMiddlename ()
 
 isMiddlenameRequired ()
 
 showSuffix ()
 
 isSuffixRequired ()
 
 getSuffixOptions ()
 
 getClassName ()
 
 getContainerClassName ()
 
 getStoreLabel ($attributeCode)
 
 getAttributeValidationClass ($attributeCode)
 
- Public Member Functions inherited from AbstractWidget
 __construct (\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Helper\Address $addressHelper, CustomerMetadataInterface $customerMetadata, array $data=[])
 
 getConfig ($key)
 
 getFieldIdFormat ()
 
 getFieldNameFormat ()
 
 getFieldId ($field)
 
 getFieldName ($field)
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Member Functions

 _showConfig ($key)
 
 _getAttribute ($attributeCode)
 
- Protected Member Functions inherited from AbstractWidget
 _getAttribute ($attributeCode)
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $addressMetadata
 
 $options
 
- Protected Attributes inherited from AbstractWidget
 $customerMetadata
 
 $_addressHelper
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Widget for showing customer name.

@method CustomerInterface getObject() @method Name setObject(CustomerInterface $customer)

@SuppressWarnings(PHPMD.DepthOfInheritance)

Definition at line 23 of file Name.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Context  $context,
AddressHelper  $addressHelper,
CustomerMetadataInterface  $customerMetadata,
Options  $options,
AddressMetadataInterface  $addressMetadata,
array  $data = [] 
)
Parameters
Context$context
AddressHelper$addressHelper
CustomerMetadataInterface$customerMetadata
Options$options
AddressMetadataInterface$addressMetadata
array$data

Definition at line 43 of file Name.php.

50  {
51  $this->options = $options;
52  parent::__construct($context, $addressHelper, $customerMetadata, $data);
53  $this->addressMetadata = $addressMetadata;
54  $this->_isScopePrivate = true;
55  }

Member Function Documentation

◆ _construct()

_construct ( )
Returns
void

Definition at line 60 of file Name.php.

61  {
62  parent::_construct();
63 
64  // default template location
65  $this->setTemplate('Magento_Customer::widget/name.phtml');
66  }

◆ _getAttribute()

_getAttribute (   $attributeCode)
protected

Definition at line 206 of file Name.php.

207  {
208  if ($this->getForceUseCustomerAttributes() || $this->getObject() instanceof CustomerInterface) {
209  return parent::_getAttribute($attributeCode);
210  }
211 
212  try {
213  $attribute = $this->addressMetadata->getAttributeMetadata($attributeCode);
214  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
215  return null;
216  }
217 
218  if ($this->getForceUseCustomerRequiredAttributes() && $attribute && !$attribute->isRequired()) {
219  $customerAttribute = parent::_getAttribute($attributeCode);
220  if ($customerAttribute && $customerAttribute->isRequired()) {
221  $attribute = $customerAttribute;
222  }
223  }
224 
225  return $attribute;
226  }
$attributeCode
Definition: extend.phtml:12

◆ _showConfig()

_showConfig (   $key)
protected

Can show config value

Parameters
string$key
Returns
bool

Definition at line 74 of file Name.php.

75  {
76  return (bool)$this->getConfig($key);
77  }

◆ getAttributeValidationClass()

getAttributeValidationClass (   $attributeCode)

Get string with frontend validation classes for attribute

Parameters
string$attributeCode
Returns
string

Definition at line 246 of file Name.php.

247  {
248  return $this->_addressHelper->getAttributeValidationClass($attributeCode);
249  }
$attributeCode
Definition: extend.phtml:12

◆ getClassName()

getClassName ( )

Class name getter

Returns
string

Definition at line 181 of file Name.php.

182  {
183  if (!$this->hasData('class_name')) {
184  $this->setData('class_name', 'customer-name');
185  }
186  return $this->getData('class_name');
187  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getContainerClassName()

getContainerClassName ( )

Container class name getter

Returns
string

Definition at line 194 of file Name.php.

195  {
196  $class = $this->getClassName();
197  $class .= $this->showPrefix() ? '-prefix' : '';
198  $class .= $this->showMiddlename() ? '-middlename' : '';
199  $class .= $this->showSuffix() ? '-suffix' : '';
200  return $class;
201  }
$_option $_optionId $class
Definition: date.phtml:13

◆ getPrefixOptions()

getPrefixOptions ( )

Retrieve name prefix drop-down options

Returns
array|bool

Definition at line 104 of file Name.php.

105  {
106  $prefixOptions = $this->options->getNamePrefixOptions();
107 
108  if ($this->getObject() && !empty($prefixOptions)) {
109  $prefixOption = $this->getObject()->getPrefix();
110  $oldPrefix = $this->escapeHtml(trim($prefixOption));
111  if ($prefixOption !== null && !isset($prefixOptions[$oldPrefix]) && !isset($prefixOptions[$prefixOption])) {
112  $prefixOptions[$oldPrefix] = $oldPrefix;
113  }
114  }
115  return $prefixOptions;
116  }

◆ getStoreLabel()

getStoreLabel (   $attributeCode)

Retrieve store attribute label

Parameters
string$attributeCode
Returns
string

Definition at line 234 of file Name.php.

235  {
237  return $attribute ? __($attribute->getStoreLabel()) : '';
238  }
__()
Definition: __.php:13
$attributeCode
Definition: extend.phtml:12
_getAttribute($attributeCode)
Definition: Name.php:206

◆ getSuffixOptions()

getSuffixOptions ( )

Retrieve name suffix drop-down options

Returns
array|bool

Definition at line 163 of file Name.php.

164  {
165  $suffixOptions = $this->options->getNameSuffixOptions();
166  if ($this->getObject() && !empty($suffixOptions)) {
167  $suffixOption = $this->getObject()->getSuffix();
168  $oldSuffix = $this->escapeHtml(trim($suffixOption));
169  if ($suffixOption !== null && !isset($suffixOptions[$oldSuffix]) && !isset($suffixOptions[$suffixOption])) {
170  $suffixOptions[$oldSuffix] = $oldSuffix;
171  }
172  }
173  return $suffixOptions;
174  }

◆ isMiddlenameRequired()

isMiddlenameRequired ( )

Define if middlename attribute is required

Returns
bool

Definition at line 133 of file Name.php.

134  {
135  return $this->_isAttributeRequired('middlename');
136  }

◆ isPrefixRequired()

isPrefixRequired ( )

Define if prefix attribute is required

Returns
bool

Definition at line 94 of file Name.php.

95  {
96  return $this->_isAttributeRequired('prefix');
97  }

◆ isSuffixRequired()

isSuffixRequired ( )

Define if suffix attribute is required

Returns
bool

Definition at line 153 of file Name.php.

154  {
155  return $this->_isAttributeRequired('suffix');
156  }

◆ showMiddlename()

showMiddlename ( )

Define if middle name attribute can be shown

Returns
bool

Definition at line 123 of file Name.php.

124  {
125  return $this->_isAttributeVisible('middlename');
126  }

◆ showPrefix()

showPrefix ( )

Can show prefix

Returns
bool

Definition at line 84 of file Name.php.

85  {
86  return $this->_isAttributeVisible('prefix');
87  }

◆ showSuffix()

showSuffix ( )

Define if suffix attribute can be shown

Returns
bool

Definition at line 143 of file Name.php.

144  {
145  return $this->_isAttributeVisible('suffix');
146  }

Field Documentation

◆ $addressMetadata

$addressMetadata
protected

Definition at line 28 of file Name.php.

◆ $options

$options
protected

Definition at line 33 of file Name.php.


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