Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultSortby.php
Go to the documentation of this file.
1 <?php
13 
14 class DefaultSortby extends \Magento\Framework\Data\Form\Element\Select
15 {
21  public function getToggleCode()
22  {
23  $htmlId = 'use_config_' . $this->getHtmlId();
24  return "toggleValueElements(this, this.parentNode.parentNode);" .
25  "if (!this.checked) toggleValueElements(\$('{$htmlId}'), \$('{$htmlId}').parentNode);";
26  }
27 
33  public function getElementHtml()
34  {
35  $elementDisabled = $this->getDisabled() == 'disabled';
36  $disabled = false;
37 
38  if (!$this->getValue() || $elementDisabled) {
39  $this->setData('disabled', 'disabled');
40  $disabled = true;
41  }
42 
43  $html = parent::getElementHtml();
44  $htmlId = 'use_config_' . $this->getHtmlId();
45  $html .= '<input id="' . $htmlId . '" name="use_config[]" value="' . $this->getId() . '"';
46  $html .= $disabled ? ' checked="checked"' : '';
47 
48  if ($this->getReadonly() || $elementDisabled) {
49  $html .= ' disabled="disabled"';
50  }
51 
52  $html .= ' onclick="toggleValueElements(this, this.parentNode);" class="checkbox" type="checkbox" />';
53  $html .= ' <label for="' . $htmlId . '" class="normal">' . __('Use Config Settings') . '</label>';
54  $html .= '<script>require(["prototype"], function(){toggleValueElements($(\'' .
55  $htmlId .
56  '\'), $(\'' .
57  $htmlId .
58  '\').parentNode);});</script>';
59 
60  return $html;
61  }
62 }
__()
Definition: __.php:13
setData($key, $value=null)
Definition: DataObject.php:72