Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Checkbox Class Reference
Inheritance diagram for Checkbox:
AbstractRenderer AbstractBlock RendererInterface AbstractBlock DataObject BlockInterface Extended Massaction

Public Member Functions

 __construct (\Magento\Backend\Block\Context $context, \Magento\Backend\Block\Widget\Grid\Column\Renderer\Options\Converter $converter, array $data=[])
 
 getValues ()
 
 render (\Magento\Framework\DataObject $row)
 
 renderHeader ()
 
- Public Member Functions inherited from AbstractRenderer
 setColumn ($column)
 
 getColumn ()
 
 render (DataObject $row)
 
 renderExport (DataObject $row)
 
 _getInputValueElement (DataObject $row)
 
 renderHeader ()
 
 renderProperty ()
 
 renderCss ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Backend\Block\Context $context, array $data=[])
 
- 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

 _getValues ()
 
 _getCheckboxHtml ($value, $checked)
 
- Protected Member Functions inherited from AbstractRenderer
 _getValue (DataObject $row)
 
 _getInputValue (DataObject $row)
 
- 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

 $_defaultWidth = 55
 
 $_values
 
 $_converter
 
- Protected Attributes inherited from AbstractRenderer
 $_defaultWidth
 
 $_column
 
- Protected Attributes inherited from AbstractBlock
 $_authorization
 
- 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 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

Grid checkbox column renderer

@api

Deprecated:
100.2.0 in favour of UI component implementation
Since
100.0.2

Definition at line 15 of file Checkbox.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Backend\Block\Context  $context,
\Magento\Backend\Block\Widget\Grid\Column\Renderer\Options\Converter  $converter,
array  $data = [] 
)
Parameters
\Magento\Backend\Block\Context$context
\Magento\Backend\Block\Widget\Grid\Column\Renderer\Options\Converter$converter
array$data

Definition at line 37 of file Checkbox.php.

41  {
42  parent::__construct($context, $data);
43  $this->_converter = $converter;
44  }

Member Function Documentation

◆ _getCheckboxHtml()

_getCheckboxHtml (   $value,
  $checked 
)
protected
Parameters
string$valueValue of the element
bool$checkedWhether it is checked
Returns
string

Definition at line 119 of file Checkbox.php.

120  {
121  $html = '<label class="data-grid-checkbox-cell-inner" ';
122  $html .= ' for="id_' . $this->escapeHtml($value) . '">';
123  $html .= '<input type="checkbox" ';
124  $html .= 'name="' . $this->getColumn()->getFieldName() . '" ';
125  $html .= 'value="' . $this->escapeHtml($value) . '" ';
126  $html .= 'id="id_' . $this->escapeHtml($value) . '" ';
127  $html .= 'class="' .
128  ($this->getColumn()->getInlineCss() ? $this->getColumn()->getInlineCss() : 'checkbox') .
129  ' admin__control-checkbox' . '"';
130  $html .= $checked . $this->getDisabled() . '/>';
131  $html .= '<label for="id_' . $this->escapeHtml($value) . '"></label>';
132  $html .= '</label>';
133  /* ToDo UI: add class="admin__field-label" after some refactoring _fields.less */
134  return $html;
135  }
$value
Definition: gender.phtml:16
$checked
Definition: billing.phtml:77

◆ _getValues()

_getValues ( )
protected

Prepare data for renderer

Returns
array

Definition at line 64 of file Checkbox.php.

65  {
66  $values = $this->getColumn()->getValues();
67  return $this->_converter->toFlatArray($values);
68  }
$values
Definition: options.phtml:88

◆ getValues()

getValues ( )

Returns values of the column

Returns
array

Definition at line 51 of file Checkbox.php.

52  {
53  if ($this->_values === null) {
54  $this->_values = $this->getColumn()->getData('values') ? $this->getColumn()->getData('values') : [];
55  }
56  return $this->_values;
57  }

◆ render()

render ( \Magento\Framework\DataObject  $row)

Renders grid column

Parameters
\Magento\Framework\DataObject$row
Returns
string @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Implements RendererInterface.

Definition at line 78 of file Checkbox.php.

79  {
80  $values = $this->_getValues();
81  $value = $row->getData($this->getColumn()->getIndex());
82  $checked = '';
83  if (is_array($values)) {
84  $checked = in_array($value, $values) ? ' checked="checked"' : '';
85  } else {
86  $checkedValue = $this->getColumn()->getValue();
87  if ($checkedValue !== null) {
88  $checked = $value === $checkedValue ? ' checked="checked"' : '';
89  }
90  }
91 
92  $disabled = '';
93  $disabledValues = $this->getColumn()->getDisabledValues();
94  if (is_array($disabledValues)) {
95  $disabled = in_array($value, $disabledValues) ? ' disabled="disabled"' : '';
96  } else {
97  $disabledValue = $this->getColumn()->getDisabledValue();
98  if ($disabledValue !== null) {
99  $disabled = $value === $disabledValue ? ' disabled="disabled"' : '';
100  }
101  }
102 
103  $this->setDisabled($disabled);
104 
105  if ($this->getNoObjectId() || $this->getColumn()->getUseIndex()) {
106  $v = $value;
107  } else {
108  $v = $row->getId() != "" ? $row->getId() : $value;
109  }
110 
111  return $this->_getCheckboxHtml($v, $checked);
112  }
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16
$checked
Definition: billing.phtml:77

◆ renderHeader()

renderHeader ( )

Renders header of the column

Returns
string

Definition at line 142 of file Checkbox.php.

143  {
144  if ($this->getColumn()->getHeader()) {
145  return parent::renderHeader();
146  }
147 
148  $checked = '';
149  if ($filter = $this->getColumn()->getFilter()) {
150  $checked = $filter->getValue() ? ' checked="checked"' : '';
151  }
152 
153  $disabled = '';
154  if ($this->getColumn()->getDisabled()) {
155  $disabled = ' disabled="disabled"';
156  }
157  $html = '<th class="data-grid-th data-grid-actions-cell"><input type="checkbox" ';
158  $html .= 'name="' . $this->getColumn()->getFieldName() . '" ';
159  $html .= 'onclick="' . $this->getColumn()->getGrid()->getJsObjectName() . '.checkCheckboxes(this)" ';
160  $html .= 'class="admin__control-checkbox"' . $checked . $disabled . ' ';
161  $html .= 'title="' . __('Select All') . '"/><label></label></th>';
162  return $html;
163  }
__()
Definition: __.php:13
$checked
Definition: billing.phtml:77

Field Documentation

◆ $_converter

$_converter
protected

Definition at line 30 of file Checkbox.php.

◆ $_defaultWidth

$_defaultWidth = 55
protected

Definition at line 20 of file Checkbox.php.

◆ $_values

$_values
protected

Definition at line 25 of file Checkbox.php.


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