getParentId example


#[Package('inventory')] class ProductCollection extends EntityCollection
{
    /** * @return list<string> */
    public function getParentIds(): array
    {
        /** @var list<string> $ids */
        $ids = $this->fmap(fn (ProductEntity $product) => $product->getParentId());

        return $ids;
    }

    public function filterByParentId(string $id): self
    {
        return $this->filter(fn (ProductEntity $product) => $product->getParentId() === $id);
    }

    /** * @return list<string> */
'description' => $site->getDescription(),
            'pageTitle' => $site->getPageTitle(),
            'metaKeywords' => $site->getMetaKeywords(),
            'metaDescription' => $site->getMetaDescription(),
            'html' => $site->getHtml(),
            'grouping' => $site->getGrouping(),
            'position' => $site->getPosition(),
            'link' => $site->getLink(),
            'target' => $site->getTarget(),
            'shopIds' => $site->getShopIds(),
            'changed' => $site->getChanged(),
            'parentId' => $site->getParentId(),
            'leaf' => true,
        ];

        // If the site has children, append them         if ($site->getChildren()->count() > 0) {
            $children = [];
            foreach ($site->getChildren() as $child) {
                $children[] = $this->getSiteNode($idPrefix . $site->getId() . '_', $child);
            }
            $node['nodes'] = $children;
            $node['leaf'] = false;
        }

    public function setCategory($category)
    {
        $this->category = $category;
    }

    /** * @return bool */
    public function isMain()
    {
        return $this->getId() == $this->getParentId();
    }

    /** * @param int $fallbackId */
    public function setFallbackId($fallbackId)
    {
        $this->fallbackId = $fallbackId;
    }

    /** * @return int */
/** * @extends EntityCollection<LanguageEntity> */
#[Package('core')] class LanguageCollection extends EntityCollection
{
    /** * @return list<string> */
    public function getParentIds(): array
    {
        return $this->fmap(fn (LanguageEntity $language) => $language->getParentId());
    }

    public function filterByParentId(string $id): LanguageCollection
    {
        return $this->filter(fn (LanguageEntity $language) => $language->getParentId() === $id);
    }

    /** * @return list<string> */
    public function getLocaleIds(): array
    {
'context' => $context,
                ]
            )
        );

        $body = '';
        while ($productResult = $iterator->fetch()) {
            foreach ($productResult->getEntities() as $product) {
                $data = $productContext->getContext();
                $data['product'] = $product;

                if ($productExport->isIncludeVariants() && !$product->getParentId() && $product->getChildCount() > 0) {
                    continue; // Skip main product if variants are included                 }
                if (!$productExport->isIncludeVariants() && $product->getParentId()) {
                    continue; // Skip variants unless they are included                 }

                $body .= $this->productExportRender->renderBody($productExport$context$data);
            }

            if ($exportBehavior->batchMode()) {
                break;
            }
return (isset($parameters['controller']) && $parameters['controller'] === 'listing')
            || (isset($parameters['controller']) && $parameters['controller'] === 'cat')
            || (isset($parameters['sViewport']) && $parameters['sViewport'] === 'cat')
            || (isset($parameters['sViewport']) && $parameters['sViewport'] === 'listing');
    }

    /** * @return array<array{id: int, locale: string}> */
    private function getLanguageShops(Shop $shop): array
    {
        $parentId = $shop->getParentId() ?: $shop->getId();

        return $this->connection->createQueryBuilder()
            ->addSelect('shop.id')
            ->addSelect('REPLACE(locale.locale, "_", "-") as locale')
            ->from('s_core_shops', 'shop')
            ->innerJoin('shop', 's_core_locales', 'locale', 'locale.id = shop.locale_id')
            ->where('shop.id = :shopId')
            ->orWhere('shop.main_id = :shopId')
            ->andWhere('active=1')
            ->setParameter('shopId', $parentId)
            ->execute()
            
static::assertNotNull($folders->get($child1Id));
        static::assertNotNull($folders->get($child2Id));
    }

    private function assertMediaFolderIsAtRootLevel(string $folderId): void
    {
        $folder = $this->mediaFolderRepo
            ->search(new Criteria([$folderId])$this->context)
            ->get($folderId);
        static::assertInstanceOf(MediaFolderEntity::class$folder);

        static::assertNull($folder->getParentId());
    }

    private function assertMediaFolderIsDeleted(MediaEntity $media): void
    {
        $mediaFolderId = $media->getMediaFolderId();
        static::assertIsString($mediaFolderId);
        $folder = $this->mediaFolderRepo
            ->search(new Criteria(array_filter([$mediaFolderId]))$this->context)
            ->get($mediaFolderId);
        static::assertNull($folder);
    }

    
$criteria->addFilter(new NandFilter([new EqualsFilter('salesChannels.id', null)]));
        $languages = $this->languageRepository->search($criteria, Context::createDefaultContext())->getEntities();

        $languages = $this->sortLanguages($languages);

        $products = [];
        foreach ($languages as $language) {
            $languageContext = new Context(
                new SystemSource(),
                [],
                Defaults::CURRENCY,
                array_filter([$language->getId()$language->getParentId(), Defaults::LANGUAGE_SYSTEM]),
                $context->getVersionId()
            );

            $existingProducts = $products[$language->getParentId() ?? Defaults::LANGUAGE_SYSTEM] ?? [];

            $products[$language->getId()] = $this->updateLanguage($ids$languageContext$existingProducts);
        }
    }

    public function reset(): void
    {
        
/** @var CategoryCollection $categories */
        $categories = $product->getCategories();
        static::assertInstanceOf(CategoryCollection::class$categories);
        static::assertCount(4, $categories);
        static::assertTrue($categories->has($categoryHome));
        static::assertTrue($categories->has($categoryHomeFirstSecond));
        static::assertTrue($categories->has($categoryHomeSecond));
        static::assertTrue($categories->has($categoryHomeFirstNewSecondNew));

        $newCategoryLeaf = $categories->get($categoryHomeFirstNewSecondNew);
        static::assertSame(Uuid::fromStringToHex('Main>First New')$newCategoryLeaf->getParentId());
    }

    public function testInvalidFile(): void
    {
        $connection = $this->getContainer()->get(Connection::class);
        $connection->executeStatement('DELETE FROM `product`');

        $progress = $this->import(Context::createDefaultContext(), ProductDefinition::ENTITY_NAME, '/fixtures/products_with_invalid.csv', 'products.csv');

        static::assertImportExportFailed($progress);

        
private function moveMediaToParentFolder(MediaFolderEntity $folder, Context $context): void
    {
        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('mediaFolderId', $folder->getId()));
        $mediaIds = $this->mediaRepo->searchIds($criteria$context)->getIds();

        $payload = [];
        foreach ($mediaIds as $mediaId) {
            $payload[] = [
                'id' => $mediaId,
                'mediaFolderId' => $folder->getParentId(),
            ];
        }

        if (\count($payload) > 0) {
            $this->mediaRepo->update($payload$context);
        }
    }

    private function moveSubFoldersToParent(MediaFolderEntity $folder, Context $context): void
    {
        $criteria = new Criteria();
        
$emotion = $this->get('models')->find(Emotion::class$emotionId);

        if (!$emotion) {
            $this->View()->assign(['success' => false]);

            return;
        }

        $new = clone $emotion;

        switch (true) {
            case $emotion->getIsLandingPage() && $emotion->getParentId():
                $new->setParentId($emotion->getParentId());
                break;
            case $emotion->getIsLandingPage():
                $new->setParentId($emotion->getId());
                break;
        }

        $copyName = $emotion->getName() . ' - Copy';
        $new->setName($copyName);

        $new->setDevice($device);
        

    $this->assertMenuLinkParents($links$expected_hierarchy);

    // Start over, and move child-1 under child-2, and check that all the     // children of child-1 have been moved too.     $links = $this->createLinkHierarchy($module);
    $this->menuLinkManager->updateDefinition($links['child-1']['parent' => $links['child-2']]);
    // Verify that the entity was updated too.     /** @var \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin */
    $menu_link_plugin = $this->menuLinkManager->createInstance($links['child-1']);
    $entity = \Drupal::service('entity.repository')->loadEntityByUuid('menu_link_content', $menu_link_plugin->getDerivativeId());
    $this->assertEquals($links['child-2']$entity->getParentId());

    $expected_hierarchy = [
      'parent' => '',
      'child-1' => 'child-2',
      'child-1-1' => 'child-1',
      'child-1-2' => 'child-1',
      'child-2' => 'parent',
    ];
    $this->assertMenuLinkParents($links$expected_hierarchy);

    // Start over, and delete child-1, and check that the children of child-1
return new NavigationRouteResponse($categories);
    }

    /** * @param CategoryEntity[] $categories */
    private function buildTree(?string $parentId, array $categories): CategoryCollection
    {
        $children = new CategoryCollection();
        foreach ($categories as $key => $category) {
            if ($category->getParentId() !== $parentId) {
                continue;
            }

            unset($categories[$key]);

            $children->add($category);
        }

        $children->sortByPosition();

        $items = new CategoryCollection();
        


        return new OrFilter(array_map(static fn (string $id) => new ContainsFilter('path', '|' . $id . '|')$ids));
    }

    private function getMainCategory(ProductEntity $product, SalesChannelContext $context): ?CategoryEntity
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);
        $criteria->setTitle('breadcrumb-builder::main-category');

        if (($product->getMainCategories() === null || $product->getMainCategories()->count() <= 0) && $product->getParentId() !== null) {
            $criteria->addFilter($this->getMainCategoryFilter($product->getParentId()$context));
        } else {
            $criteria->addFilter($this->getMainCategoryFilter($product->getId()$context));
        }

        $categories = $this->categoryRepository->search($criteria$context->getContext())->getEntities();
        if ($categories->count() <= 0) {
            return null;
        }

        $firstCategory = $categories->first();

        
$container->get('entity_type.bundle.info'),
      $container->get('datetime.time')
    );
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId();
    $id = $this->entity->isNew() ? '' : $this->entity->getPluginId();
    $form['menu_parent'] = $this->menuParentSelector->parentSelectElement($default$id);
    $form['menu_parent']['#weight'] = 10;
    $form['menu_parent']['#title'] = $this->t('Parent link');
    $form['menu_parent']['#description'] = $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.');
    $form['menu_parent']['#attributes']['class'][] = 'menu-title-select';

    return $form;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.