Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ElementFactory.php
Go to the documentation of this file.
1 <?php
11 
13 {
14  const OUTPUT_FORMAT_JSON = 'json';
15  const OUTPUT_FORMAT_TEXT = 'text';
16  const OUTPUT_FORMAT_HTML = 'html';
17  const OUTPUT_FORMAT_PDF = 'pdf';
18  const OUTPUT_FORMAT_ONELINE = 'oneline';
19  const OUTPUT_FORMAT_ARRAY = 'array';
20 
21  // available only for multiply attributes
22 
23  // available only for multiply attributes
24  protected $_objectManager;
25 
29  protected $_string;
30 
35  public function __construct(
36  \Magento\Framework\ObjectManagerInterface $objectManager,
37  \Magento\Framework\Stdlib\StringUtils $string
38  ) {
39  $this->_objectManager = $objectManager;
40  $this->_string = $string;
41  }
42 
52  public function create(
54  $value,
56  $isAjax = false
57  ) {
58  $dataModelClass = $attribute->getDataModel();
59  $params = [
60  'entityTypeCode' => $entityTypeCode,
61  'value' => $value === null ? false : $value,
62  'isAjax' => $isAjax,
63  'attribute' => $attribute,
64  ];
66  if ($dataModelClass == \Magento\Customer\Model\Attribute\Data\Postcode::class) {
67  $dataModelClass = \Magento\Customer\Model\Metadata\Form\Postcode::class;
68  }
69  if (!empty($dataModelClass)) {
70  $dataModel = $this->_objectManager->create($dataModelClass, $params);
71  } else {
72  $dataModelClass = sprintf(
73  'Magento\Customer\Model\Metadata\Form\%s',
74  $this->_string->upperCaseWords($attribute->getFrontendInput())
75  );
76  $dataModel = $this->_objectManager->create($dataModelClass, $params);
77  }
78 
79  return $dataModel;
80  }
81 }
$objectManager
Definition: bootstrap.php:17
return false
Definition: gallery.phtml:36
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Framework\Stdlib\StringUtils $string)
$value
Definition: gender.phtml:16
create(\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute, $value, $entityTypeCode, $isAjax=false)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18