Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeSetManagement.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Eav\Model;
7 
11 use Magento\Eav\Model\Config as EavConfig;
13 
15 {
19  private $eavConfig;
20 
24  private $repository;
25 
31  public function __construct(
32  EavConfig $eavConfig,
34  ) {
35  $this->eavConfig = $eavConfig;
36  $this->repository = $repository;
37  }
38 
42  public function create($entityTypeCode, AttributeSetInterface $attributeSet, $skeletonId)
43  {
45  if ($attributeSet->getId() !== null) {
47  }
48  if ($skeletonId == 0) {
49  throw InputException::invalidFieldValue('skeletonId', $skeletonId);
50  }
51  // Make sure that skeleton attribute set is valid (try to load it)
52  $this->repository->get($skeletonId);
53 
54  try {
55  $attributeSet->setEntityTypeId($this->eavConfig->getEntityType($entityTypeCode)->getId());
56  $attributeSet->validate();
57  } catch (\Exception $exception) {
58  throw new InputException(__($exception->getMessage()));
59  }
60 
61  $this->repository->save($attributeSet);
62  $attributeSet->initFromSkeleton($skeletonId);
63 
64  return $this->repository->save($attributeSet);
65  }
66 }
__construct(EavConfig $eavConfig, AttributeSetRepositoryInterface $repository)
static invalidFieldValue($fieldName, $fieldValue, \Exception $cause=null)
__()
Definition: __.php:13
create( $entityTypeCode, \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet, $skeletonId)