getReference example

/** @var \Drupal\Core\Http\LinkRelationTypeManager $link_relation_type_manager */
    $link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type');

    // A link relation type of the "registered" kind.     /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
    $canonical = $link_relation_type_manager->createInstance('canonical');
    $this->assertInstanceOf(LinkRelationType::class$canonical);
    $this->assertTrue($canonical->isRegistered());
    $this->assertFalse($canonical->isExtension());
    $this->assertSame('canonical', $canonical->getRegisteredName());
    $this->assertNull($canonical->getExtensionUri());
    $this->assertEquals('[RFC6596]', $canonical->getReference());
    $this->assertEquals('Designates the preferred version of a resource (the IRI and its contents).', $canonical->getDescription());
    $this->assertEquals('', $canonical->getNotes());

    // A link relation type of the "extension" kind.     /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
    $add_form = $link_relation_type_manager->createInstance('add-form');
    $this->assertInstanceOf(LinkRelationType::class$add_form);
    $this->assertFalse($add_form->isRegistered());
    $this->assertTrue($add_form->isExtension());
    $this->assertNull($add_form->getRegisteredName());
    $this->assertSame('https://drupal.org/link-relations/add-form', $add_form->getExtensionUri());
    

        $builder->get('reference')->add('firstName', TextTypeTest::TESTED_TYPE);
        $form = $builder->getForm();

        $form->submit([
            // reference has a getter, but no setter             'reference' => [
                'firstName' => 'Foo',
            ],
        ]);

        $this->assertEquals('Foo', $author->getReference()->firstName);
    }

    public function testSubformCallsSettersIfTheObjectChanged()
    {
        // no reference         $author = new FormTest_AuthorWithoutRefSetter(null);
        $newReference = new Author();

        $builder = $this->factory->createBuilder(static::TESTED_TYPE, $author);
        $builder->add('referenceCopy', static::TESTED_TYPE, [
            'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
        ]);
return;
        }

        $group = $this->get('models')->getRepository(Group::class)->find($setId);
        if ($group === null) {
            $this->View()->assign(['success' => false, 'message' => 'Group not found']);

            return;
        }

        $option = $this->get('models')->getReference(Option::class$optionId);
        if ($option === null) {
            $this->View()->assign(['success' => false, 'message' => 'Option not found']);

            return;
        }

        $group->addOption($option);

        try {
            $this->get('models')->flush();
        } catch (\Exception $e) {
            
// Tested this with ~140k products - compared with pure SQL this is reasonable fast         // In most cases the filter query will be the bottleneck         $i = 0;
        $model = null;
        foreach ($results as $detailId) {
            // Flush after 20 entities             if (($i++ % 20) === 0) {
                $entityManager->flush($model);
                $entityManager->clear();

                /** @var QueueModel $queue */
                $queue = $entityManager->getReference(QueueModel::class$queueId);
            }

            /** @var Detail $detail */
            $detail = $entityManager->getReference(\Shopware\Models\Article\Detail::class$detailId);

            $model = new QueueArticle();
            $model->setQueue($queue);
            $model->setDetail($detail);
            $entityManager->persist($model);
        }

        
protected function assignRecipients(Log $logEntry, array $recipients = []): void
    {
        $knownRecipients = $this->getKnownRecipients($recipients);
        $unknownRecipients = array_flip($recipients);

        $associatedContacts = [];

        foreach ($knownRecipients as $recipient) {
            unset($unknownRecipients[$recipient['mail_address']]);

            $contact = $this->entityManager->getReference(
                Contact::class,
                $recipient['id']
            );
            if ($contact instanceof Contact) {
                $associatedContacts[] = $contact;
            }
        }

        foreach (array_keys($unknownRecipients) as $recipient) {
            $contact = new Contact();
            $contact->setMailAddress((string) $recipient);

            

    protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable$ruleKey)
    {
        $parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
        $map = $dependentTable->getReference($parentTableName$ruleKey);

        if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
            $parentInfo = $parentTable->info();
            $map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
        }

        $map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
        $map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];

        return $map;
    }

    


            if (!($element instanceof Element)) {
                continue;
            }

            $value = $this->getElementShopValue(
                $element->getValues(),
                $data['shopId']
            );

            $shop = $this->entityManager->getReference(Shop::class$data['shopId']);
            if (!$shop instanceof Shop) {
                throw new ModelNotFoundException(Shop::class$data['shopId']);
            }

            if ($element->getType() === 'theme-media-selection') {
                $data['value'] = $this->mediaService->normalize($data['value']);
            }

            // Don't save default values             if ($element->getDefaultValue() === $data['value']) {
                $element->getValues()->removeElement($value);
                

    protected function sSaveComment($commentData$blogArticleId)
    {
        if (empty($commentData)) {
            throw new Enlight_Exception('sSaveComment #00: Could not save comment');
        }

        $blogCommentModel = new Comment();
        /** @var Blog $blog */
        $blog = $this->getRepository()->find($blogArticleId);
        /** @var Shop $shop */
        $shop = $this->getModelManager()->getReference(Shop::class$this->get('shop')->getId());

        $blogCommentModel->setBlog($blog);
        $blogCommentModel->setCreationDate(new DateTime());
        $blogCommentModel->setActive(false);

        $blogCommentModel->setName($commentData['name']);
        $blogCommentModel->setEmail($commentData['eMail']);
        $blogCommentModel->setHeadline($commentData['headline']);
        $blogCommentModel->setComment($commentData['comment']);
        $blogCommentModel->setPoints($commentData['points']);
        $blogCommentModel->setShop($shop);

        

            if (empty($mappingData['id'])) {
                $mapping = new Mapping();
            } else {
                $mapping = $this->get('models')->find(Mapping::class$mappingData['id']);
            }

            $mapping->getRules()->clear();
            $options = [];
            foreach ($mappingData['rules'] as $ruleData) {
                $rule = new Rule();
                $option = $this->get('models')->getReference(Option::class$ruleData['optionId']);
                $rule->setMapping($mapping);
                $rule->setOption($option);
                $mapping->getRules()->add($rule);
                $options[] = $option;
            }
            $mapping->setImage($image);
            $this->get('models')->persist($mapping);
            $this->createImagesForOptions($options$imageData$image);
            $mappingModels[] = $mapping;
        }
        $image->setMappings($mappingModels);
        
private readonly ?string $shopwareVersionRevision;

    public function __construct(
        string $environment,
        bool $debug
    ) {
        parent::__construct($environment$debug);

        // @codeCoverageIgnoreStart - not testable, as static calls cannot be mocked         if (InstalledVersions::isInstalled('shopware/platform')) {
            $version = InstalledVersions::getVersion('shopware/platform')
                . '@' . InstalledVersions::getReference('shopware/platform');
        } else {
            $version = InstalledVersions::getVersion('shopware/core')
                . '@' . InstalledVersions::getReference('shopware/core');
        }
        // @codeCoverageIgnoreEnd
        $version = VersionParser::parseShopwareVersion($version);
        $this->shopwareVersion = $version['version'];
        $this->shopwareVersionRevision = $version['revision'];
    }

    
return new HttpKernelResult($transformed$event->getResponse());
    }

    private function createKernel(): KernelInterface
    {
        if ($this->kernel !== null) {
            return $this->kernel;
        }

        if (InstalledVersions::isInstalled('shopware/platform')) {
            $shopwareVersion = InstalledVersions::getVersion('shopware/platform')
                . '@' . InstalledVersions::getReference('shopware/platform');
        } else {
            $shopwareVersion = InstalledVersions::getVersion('shopware/core')
                . '@' . InstalledVersions::getReference('shopware/core');
        }

        $middlewares = [];
        if (\PHP_SAPI !== 'cli' && $this->environment !== 'prod' && InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
            $middlewares = [new ProfilingMiddleware()];
        }

        $connection = self::getConnection($middlewares);

        

    }

    /** * saves the positions of all children of this parent category */
    public function saveNewChildPositionsAction()
    {
        $ids = json_decode($this->Request()->getParam('ids'));
        foreach ($ids as $key => $categoryId) {
            /** @var Category $category */
            $category = $this->em->getReference(Category::class(int) $categoryId);
            $category->setPosition($key);
        }
        $this->em->flush();

        $this->View()->assign(['success' => true]);
    }

    /** * @deprecated in 5.6, will be private in 5.8 * * Saves a single category. If no category id is passed, * the save function will create a new category model and persist * it. * * To successful saving a category a parent category id must supplied. */


        return $value;
    }

    private function buildReferencePriceDefinition(ReferencePriceDto $definition, UnitCollection $units): ?ReferencePriceDefinition
    {
        if (
            $definition->getPurchase() === null
            || $definition->getPurchase() <= 0
            || $definition->getUnitId() === null
            || $definition->getReference() === null
            || $definition->getReference() <= 0
            || $definition->getPurchase() === $definition->getReference()
        ) {
            return null;
        }

        $unit = $units->get($definition->getUnitId());
        if ($unit === null) {
            return null;
        }

        
foreach ($entity->getFields() as $field) {
                if ($field instanceof OneToManyField) {
                    $this->validateAssociation($field);
                }
            }
        }
    }

    private function validateAssociation(OneToManyField $field): void
    {
        $reference = $field->getReference();

        // reference on custom entity table         if (\str_starts_with($reference, 'custom_entity_') || \str_starts_with($reference, 'ce_')) {
            return;
        }

        if ($field->getOnDelete() === AssociationField::CASCADE) {
            throw new \RuntimeException(\sprintf('Cascade delete and referencing core tables are not allowed, field %s', $field->getName()));
        }

        if ($field->isReverseRequired()) {
            


        return new self(
            $product->getPurchaseUnit(),
            $product->getReferenceUnit(),
            $product->getUnitId()
        );
    }

    public static function createFromCheapestPrice(CheapestPrice $price): ReferencePriceDto
    {
        return new ReferencePriceDto($price->getPurchase()$price->getReference()$price->getUnitId());
    }

    public function getPurchase(): ?float
    {
        return $this->purchase;
    }

    public function setPurchase(?float $purchase): void
    {
        $this->purchase = $purchase;
    }

    
Home | Imprint | This part of the site doesn't use cookies.