/** * {@inheritdoc} * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function save($sku, LinkInterface $link, $isGlobalScopeContent = true) { $product = $this->productRepository->get($sku, true); //ToDo: before validation link should have link_file_content //if (!$this->contentValidator->isValid($link)) { // throw new InputException(__('Provided link information is invalid.')); //} if (!in_array($link->getLinkType(), ['url', 'file'])) { throw new InputException(__('Invalid link type.')); } $title = $link->getTitle(); if (empty($title)) { throw new InputException(__('Link title cannot be empty.')); } $metadata = $this->metadataPool->getMetadata(ProductInterface::class); $link->setProductId($product->getData($metadata->getLinkField())); $this->setFiles($link); $this->resourceModel->save($link); return $link->getId(); }