Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GenericMetadata.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class GenericMetadata extends \Magento\Backend\Block\Widget\Form\Generic
16 {
21 
29  public function __construct(
30  \Magento\Backend\Block\Template\Context $context,
31  \Magento\Framework\Registry $registry,
32  \Magento\Framework\Data\FormFactory $formFactory,
33  \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
34  array $data = []
35  ) {
36  $this->dataObjectProcessor = $dataObjectProcessor;
37  parent::__construct($context, $registry, $formFactory, $data);
38  }
39 
48  protected function _setFieldset($attributes, $fieldset, $exclude = [])
49  {
50  $this->_addElementTypes($fieldset);
51 
52  foreach ($attributes as $attribute) {
53  // Note, ignoring whether its visible or not,
54  if (($inputType = $attribute->getFrontendInput()) && !in_array(
55  $attribute->getAttributeCode(),
56  $exclude
57  ) && ('media_image' != $inputType || $attribute->getAttributeCode() == 'image')
58  ) {
59  $fieldType = $inputType;
60  $element = $fieldset->addField(
61  $attribute->getAttributeCode(),
62  $fieldType,
63  [
64  'name' => $attribute->getAttributeCode(),
65  'label' => __($attribute->getFrontendLabel()),
66  'class' => $attribute->getFrontendClass(),
67  'required' => $attribute->isRequired(),
68  'note' => $attribute->getNote()
69  ]
70  );
71 
72  $element->setAfterElementHtml($this->_getAdditionalElementHtml($element));
73 
75  }
76  }
77  }
78 
88  $inputType,
89  $element,
91  ) {
92  switch ($inputType) {
93  case 'select':
94  $element->setValues($this->_getAttributeOptionsArray($attribute));
95  break;
96  case 'multiselect':
97  $element->setValues($this->_getAttributeOptionsArray($attribute));
98  $element->setCanBeEmpty(true);
99  break;
100  case 'date':
101  $element->setDateFormat($this->_localeDate->getDateFormatWithLongYear());
102  break;
103  case 'multiline':
104  $element->setLineCount($attribute->getMultilineCount());
105  break;
106  default:
107  break;
108  }
109  }
110 
116  {
117  $options = $attribute->getOptions();
118  $result = [];
119  foreach ($options as $option) {
120  $result[] = $this->dataObjectProcessor->buildOutputDataArray(
121  $option,
122  \Magento\Customer\Api\Data\OptionInterface::class
123  );
124  }
125  return $result;
126  }
127 }
_addElementTypes(\Magento\Framework\Data\Form\AbstractForm $baseElement)
Definition: Form.php:255
__()
Definition: __.php:13
_applyTypeSpecificConfigCustomer( $inputType, $element, AttributeMetadataInterface $attribute)
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, array $data=[])
$attributes
Definition: matrix.phtml:13
_getAttributeOptionsArray(AttributeMetadataInterface $attribute)
$element
Definition: element.phtml:12