ItemFactoryInterface
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
Methods¶
                
createContentIdItem()
            ¶
    
        Creates a menu item based on a given content object id.
| 
                     | 
                
                    
                     | 
            
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
                
createContentItem()
            ¶
    
        Creates a menu item based on a given content object.
| 
                     | 
                
                    
                     | 
            
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
                
createItem()
            ¶
    
        Creates a menu item based on a given name.
| 
                     | 
                
                    
                     | 
            
Parameters
| Name | Type | Default value | Description | 
|---|---|---|---|
| $name | string | - | - | 
| $options | array<string, mixed> | [] | 
                                                         Additional options for the menu item.  | 
                
Return values
ItemInterface
                
createLocationIdItem()
            ¶
    
        Creates a menu item based on a given location id.
| 
                     | 
                
                    
                     | 
            
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
                
createLocationItem()
            ¶
    
        Creates a menu item based on a given location.
| 
                     | 
                
                    
                     | 
            
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
                
createProductItem()
            ¶
    
        Creates a menu item based on a given product.
| 
                     | 
                
                    
                     | 
            
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
                
createTaxonomyEntryItem()
            ¶
    
        Creates a menu item based on a given taxonomy entry.
| 
                     | 
                
                    
                     | 
            
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