Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Build.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\Exception\AlreadyExistsException;
9 
10 class Build
11 {
16 
20  protected $name;
21 
25  protected $entityTypeId;
26 
30  protected $skeletonId;
31 
35  public function __construct(
36  \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
37  ) {
38  $this->attributeSetFactory = $attributeSetFactory;
39  }
40 
45  public function setEntityTypeId($entityTypeId)
46  {
47  $this->entityTypeId = (int)$entityTypeId;
48  return $this;
49  }
50 
55  public function setSkeletonId($skeletonId)
56  {
57  $this->skeletonId = (int)$skeletonId;
58  return $this;
59  }
60 
65  public function setName($setName)
66  {
67  $this->name = $setName;
68  return $this;
69  }
70 
75  public function getAttributeSet()
76  {
77  $this->validateParameters();
79  $attributeSet = $this->attributeSetFactory->create();
80  $attributeSet->setEntityTypeId($this->entityTypeId)->load($this->name, 'attribute_set_name');
81  if ($attributeSet->getId()) {
82  throw new AlreadyExistsException(__('Attribute Set already exists.'));
83  }
84 
85  $attributeSet->setAttributeSetName($this->name)->validate();
86  $attributeSet->save();
87  $attributeSet->initFromSkeleton($this->skeletonId)->save();
88 
89  return $attributeSet;
90  }
91 
96  protected function validateParameters()
97  {
98  if (empty($this->name)) {
99  throw new \InvalidArgumentException();
100  } elseif (empty($this->skeletonId)) {
101  throw new \InvalidArgumentException();
102  } elseif (empty($this->entityTypeId)) {
103  throw new \InvalidArgumentException();
104  }
105  }
106 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory)
Definition: Build.php:35
__()
Definition: __.php:13