Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Core Laravel Package

ibexa/core

Ibexa Core is the foundation of the Ibexa DXP, providing the PHP domain model, repository API, content types, users, permissions, search, and persistence layer integrations. It powers content management features and serves as the base for higher-level Ibexa packages.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require ibexa/core
    

    For Symfony integration, follow the official docs.

  2. First Use Case: Fetch and render a content item in a controller:

    use Ibexa\Contracts\Core\Repository\Repository;
    use Ibexa\Contracts\Core\Repository\Values\Content\Content;
    
    public function showContent(Repository $repository, int $contentId): Response
    {
        $contentService = $repository->getContentService();
        $content: Content = $contentService->load($contentId);
    
        return $this->render('content/show.html.twig', [
            'content' => $content,
        ]);
    }
    
  3. Key Entry Points:

    • Repository: Central access point ($repository = $container->get('ibexa.repository')).
    • Content Service: CRUD operations for content ($repository->getContentService()).
    • Search Service: Query content ($repository->getSearchService()).
    • Twig Integration: Use {{ ibexa.render(content) }} in templates.
  4. Configuration: Override default settings in config/packages/ibexa.yaml:

    ibexa:
        system:
            default:
                content_types:
                    group_name: 'YourGroup'
    

Implementation Patterns

Core Workflows

1. Content Management

  • Create/Update Content:

    $contentService = $repository->getContentService();
    $contentCreateStruct = $contentService->newContentCreateStruct('article');
    $contentCreateStruct->setField('title', 'My Article');
    $content = $contentService->create($contentCreateStruct, $parentLocationId);
    $contentService->publishVersion($content->versionInfo);
    
  • Bulk Operations: Use ContentService::load() + ContentService::update() in loops, or leverage the Content API for complex logic.

  • Field Handling:

    $field = $content->getField('image');
    $fieldValue = $field->value; // For simple fields
    $binaryFile = $field->getBinaryFile(); // For binary fields (e.g., images)
    

2. Search & Querying

  • Basic Search:

    $searchService = $repository->getSearchService();
    $query = new Query\Query();
    $query->query = new Query\Criteria\Query();
    $query->query->filter = new Query\Criteria\Filter\Operator\Equals\ContentType('article');
    $searchResult = $searchService->findContent($query);
    
  • Advanced Criteria: Combine filters, sorting, and aggregations:

    $query->query->filter = new Query\Criteria\LogicalAnd([
        new Query\Criteria\Filter\Operator\Equals\ContentType('article'),
        new Query\Criteria\Filter\Operator\Equals\ContentLanguage('eng-GB'),
    ]);
    $query->query->sortClauses = [
        new Query\Criteria\SortClause\Content\DatePublished(Query\Criteria\SortClause\SortClause::DIRECTION_DESC),
    ];
    
  • Embedding Search (v5+):

    $embeddingSearchService = $repository->getEmbeddingSearchService();
    $results = $embeddingSearchService->search('query text', 5);
    

3. Location & Hierarchy

  • Traverse Tree:
    $locationService = $repository->getLocationService();
    $children = $locationService->load($parentLocationId)->getChildren();
    
  • Move Content:
    $locationService->move($content->getLocation(), $newParentLocationId);
    

4. User & Permissions

  • Check Access:
    $securityService = $repository->getSecurityService();
    if ($securityService->checkPolicy($content, 'read')) {
        // Granted
    }
    
  • Role Assignment:
    $userService = $repository->getUserService();
    $user = $userService->loadUser('admin');
    $userService->assignRole($user, $role, $content);
    

5. Twig Integration

  • Render Content:
    {{ ibexa.render(content, {
        'viewType': 'full',
        'template': 'content/teaser.html.twig'
    }) }}
    
  • Field-Specific Rendering:
    {% set image = ibexa.field(content, 'image') %}
    <img src="{{ ibexa.image(image, 'original') }}" alt="{{ image.alt }}">
    

6. Commands & CLI

  • Run Migrations:
    php bin/console ibexa:io:migrate-files
    
  • Custom Commands: Extend Ibexa\Core\Base\IbexaCommand and inject the Repository:
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $repository = $this->getContainer()->get('ibexa.repository');
        // Logic here
    }
    

Integration Tips

Symfony Integration

  • Dependency Injection: Tag services for Ibexa integration:
    services:
        App\Service\MyService:
            tags: ['ibexa.content_type']
    
  • Event Listeners: Listen to Ibexa events (e.g., ContentPublish, ContentUnpublish):
    use Ibexa\Core\Event\Content\PublishEvent;
    
    public function onContentPublish(PublishEvent $event): void
    {
        $content = $event->getContent();
        // Logic
    }
    

Field Type Extensions

  • Custom Field Types: Implement Ibexa\Core\FieldType\FieldType and register in services.yaml:
    Ibexa\Core\FieldType\FieldTypeCollection:
        arguments:
            - '@App\FieldType\MyFieldType'
    

External Storage

  • Configure Storage:
    ibexa:
        storage:
            default:
                external_storage:
                    s3:
                        enabled: true
                        bucket: 'my-bucket'
                        endpoint: 's3.amazonaws.com'
    

API Platform (v5+)

  • Expose Content as API: Use Ibexa\Core\Api\ApiResource annotations:
    use Ibexa\Core\Api\ApiResource;
    
    #[ApiResource]
    class ArticleController extends AbstractController
    {
        #[Get('/articles/{id}')]
        public function getArticle(int $id): Content
        {
            return $this->repository->getContentService()->load($id);
        }
    }
    

Gotchas and Tips

Pitfalls

  1. SiteAccess Context:

    • Issue: Forgetting to set the SiteAccess context can lead to unexpected behavior (e.g., wrong language or content visibility).
    • Fix: Always specify the siteaccess in queries or services:
      $repository->setCurrentSiteAccess('site1');
      
    • Debug Tip: Use dd($repository->getCurrentSiteAccess()) to verify.
  2. Content Versioning:

    • Issue: Modifying a published version directly (use drafts instead).
    • Fix: Always work with drafts:
      $contentService->loadDraft($contentId);
      
  3. Field Value Serialization:

    • Issue: Directly casting field values to strings/arrays can break binary fields (e.g., images).
    • Fix: Use Field::value for simple fields, Field::getBinaryFile() for binaries.
  4. Search Indexing:

    • Issue: Changes to content types or fields may require reindexing.
    • Fix: Run:
      php bin/console ibexa:search:reindex
      
  5. Circular References:

    • Issue: Deeply nested content/location structures can cause stack overflows.
    • Fix: Use lazy loading or pagination:
      $location->getChildren(['limit' => 10]);
      
  6. Twig Caching:

    • Issue: Cached Twig templates may not reflect changes to field templates.
    • Fix: Clear cache or use {{ ibexa.render(content, {'cache' => false}) }}.
  7. Permission Inheritance:

    • Issue: Overriding permissions at the content level can break inheritance.
    • Fix: Use SecurityService::setPolicy() carefully and test inheritance chains.

Debugging Tips

  1. Enable Debug Mode:

    ibexa:
        debug: true
    
    • Logs SQL queries, search queries, and repository events.
  2. Query Logging:

    • Enable Doctrine logging for search
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor