Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Public Member Functions | Protected Member Functions
Button Class Reference
Inheritance diagram for Button:
Template ControlInterface AbstractBlock BlockInterface DataObject BlockInterface SplitButton

Public Member Functions

 getType ()
 
 getAttributesHtml ()
 
 getOnClick ()
 
- 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

 _construct ()
 
 getTemplatePath ()
 
 prepareAttributes ($title, $classes, $disabled)
 
 attributesToHtml ($attributes)
 
- 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)
 

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_'
 
- 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 = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Class Button

Definition at line 14 of file Button.php.

Member Function Documentation

◆ _construct()

_construct ( )
protected

Define block template

Returns
void

Definition at line 21 of file Button.php.

22  {
23  $this->setTemplate($this->getTemplatePath());
24 
25  parent::_construct();
26  }

◆ attributesToHtml()

attributesToHtml (   $attributes)
protected

Attributes list to html

Parameters
array$attributes
Returns
string

Definition at line 130 of file Button.php.

131  {
132  $html = '';
133  foreach ($attributes as $attributeKey => $attributeValue) {
134  if ($attributeValue === null || $attributeValue == '') {
135  continue;
136  }
137  $html .= $attributeKey . '="' . $this->escapeHtmlAttr($attributeValue, false) . '" ';
138  }
139 
140  return $html;
141  }
$attributes
Definition: matrix.phtml:13
escapeHtmlAttr($string, $escapeSingleQuote=true)

◆ getAttributesHtml()

getAttributesHtml ( )

Retrieve attributes html

Returns
string

Definition at line 57 of file Button.php.

58  {
59  $disabled = $this->getDisabled() ? 'disabled' : '';
60  $title = $this->getTitle();
61  if (empty($title)) {
62  $title = $this->getLabel();
63  }
64  $classes = ['action-', 'scalable'];
65  if ($this->hasData('class')) {
66  $classes[] = $this->getClass();
67  }
68  if ($disabled) {
69  $classes[] = $disabled;
70  }
71 
72  return $this->attributesToHtml($this->prepareAttributes($title, $classes, $disabled));
73  }
$title
Definition: default.phtml:14
prepareAttributes($title, $classes, $disabled)
Definition: Button.php:102

◆ getOnClick()

getOnClick ( )

Retrieve onclick handler

Returns
string|null

Definition at line 80 of file Button.php.

81  {
82  if ($this->hasData('on_click')) {
83  return $this->getData('on_click');
84  } else {
85  $url = $this->hasData('url') ? $this->getData('url') : $this->getUrl();
86  if (!empty($url)) {
87  return sprintf("location.href = '%s';", $url);
88  }
89 
90  return null;
91  }
92  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getTemplatePath()

getTemplatePath ( )
protected

Retrieve template path

Returns
string

Definition at line 33 of file Button.php.

34  {
35  return 'Magento_Ui::control/button/default.phtml';
36  }

◆ getType()

getType ( )

Retrieve button type

Returns
string

Definition at line 43 of file Button.php.

44  {
45  if (in_array($this->getData('type'), ['reset', 'submit'])) {
46  return $this->getData('type');
47  }
48 
49  return 'button';
50  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ prepareAttributes()

prepareAttributes (   $title,
  $classes,
  $disabled 
)
protected

Prepare attributes

Parameters
string$title
array$classes
string$disabled
Returns
array

Definition at line 102 of file Button.php.

103  {
104  $attributes = [
105  'id' => $this->getId(),
106  'name' => $this->getElementName(),
107  'title' => $title,
108  'type' => $this->getType(),
109  'class' => implode(' ', $classes),
110  'onclick' => $this->getOnClick(),
111  'style' => $this->getStyle(),
112  'value' => $this->getValue(),
113  'disabled' => $disabled,
114  ];
115  if ($this->getDataAttribute()) {
116  foreach ($this->getDataAttribute() as $key => $attr) {
117  $attributes['data-' . $key] = is_scalar($attr) ? $attr : json_encode($attr);
118  }
119  }
120 
121  return $attributes;
122  }
$title
Definition: default.phtml:14
$attr
Definition: text.phtml:8
$attributes
Definition: matrix.phtml:13

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