Copied!

ItemFactoryInterface

ItemFactoryInterface.php : 59

The item factory provides convenient methods to build menu item based on repository objects, including:.

  • Content
  • Content ID
  • Location
  • Location ID
  • Taxonomy entry
  • Product

The following example demonstrates how to build a menu (using the item factory) using child locations of a given location:

namespace App\Menu;

use Ibexa\Contracts\Core\Repository\LocationService;
use Ibexa\Contracts\Storefront\Menu\ItemFactoryInterface;
use Knp\Menu\ItemInterface;

final class LocationMenuBuilder
{
    public function __construct(
        private ItemFactoryInterface $itemFactory,
        private LocationService $locationService
    ) }

    public function build(array $options): ItemInterface
    {
        $menu = $this->itemFactory->createItem('root');

        $children = $this->locationService->loadLocationChildren($options['location'], 0, 10);
        foreach ($children as $child) {
            $menu->addChild($this->itemFactory->createLocationItem($child));
        }

        return $menu;
    }
}
Tags
See
https://symfony.com/bundles/KnpMenuBundle/current/index.html#create-your-first-menu

Methods

publiccreateContentIdItem()

ItemFactoryInterface.php : 79

Creates a menu item based on a given content object id.

public createContentIdItem(int $contentId[, string|null $name = null ][, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$contentId int - -
$name string|null null

The name of the menu item. If null, the content name is used.

$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface

publiccreateContentItem()

ItemFactoryInterface.php : 67

Creates a menu item based on a given content object.

public createContentItem(Content $content[, string|null $name = null ][, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$content Content - -
$name string|null null

The name of the menu item. If null, the content name is used.

$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface

publiccreateItem()

ItemFactoryInterface.php : 138

Creates a menu item based on a given name.

public createItem(string $name[, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$name string - -
$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface

publiccreateLocationIdItem()

ItemFactoryInterface.php : 103

Creates a menu item based on a given location id.

public createLocationIdItem(int $locationId[, string|null $name = null ][, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$locationId int - -
$name string|null null

The name of the menu item. If null, the content name of content associated with the location is used.

$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface

publiccreateLocationItem()

ItemFactoryInterface.php : 91

Creates a menu item based on a given location.

public createLocationItem(Location $location[, string|null $name = null ][, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$location Location - -
$name string|null null

The name of the menu item. If null, the content name of content associated with the location is used.

$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface

publiccreateProductItem()

ItemFactoryInterface.php : 127

Creates a menu item based on a given product.

public createProductItem(ContentAwareProductInterface $product[, string|null $name = null ][, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$product ContentAwareProductInterface - -
$name string|null null

The name of the menu item. If null, the product name is used.

$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface

publiccreateTaxonomyEntryItem()

ItemFactoryInterface.php : 115

Creates a menu item based on a given taxonomy entry.

public createTaxonomyEntryItem(TaxonomyEntry $taxonomyEntry[, string|null $name = null ][, array<string, mixed> $options = [] ]) : ItemInterface

Parameters

Name Type Default value Description
$taxonomyEntry TaxonomyEntry - -
$name string|null null

The name of the menu item. If null, the taxonomy name is used.

$options array<string, mixed> []

Additional options for the menu item.

Return values

ItemInterface