Weave 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

Tied Content Bundle Laravel Package

anh/tied-content-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require anh/tied-content-bundle
    

    Add to config/bundles.php (Symfony):

    Anh\TiedContentBundle\AnhTiedContentBundle::class => ['all' => true],
    
  2. First Use Case

    • Define a tied content relationship between two content types (e.g., Article and RelatedVideo).
    • Example in a migration or entity listener:
      use Anh\TiedContentBundle\Model\TiedContentInterface;
      
      // Assume $article is an Article entity with TiedContentInterface
      $article->addTiedContent($relatedVideo, 'related_videos');
      $article->save();
      
  3. Key Files to Explore

    • src/Resources/config/services.xml (Symfony DI config)
    • src/Model/TiedContentInterface.php (Core interface)
    • src/DependencyInjection/ (Bundle configuration)

Implementation Patterns

Common Workflows

  1. Defining Tied Content Relationships

    • Implement TiedContentInterface in your entities:
      use Anh\TiedContentBundle\Model\TiedContentInterface;
      
      class Article implements TiedContentInterface
      {
          private $tiedContents = [];
      
          public function addTiedContent($content, string $relationName): void
          {
              $this->tiedContents[$relationName][] = $content;
          }
      
          public function getTiedContents(string $relationName): array
          {
              return $this->tiedContents[$relationName] ?? [];
          }
      }
      
  2. Querying Tied Content

    • Use the bundle’s repository methods (if provided) or Doctrine queries:
      $article = $articleRepo->find($id);
      $relatedVideos = $article->getTiedContents('related_videos');
      
  3. Admin Integration (Symfony Admin Bundle)

    • Extend the bundle’s admin configuration to support tied content:
      # config/admin.yml
      anh_content:
          tied_content:
              Article:
                  related_videos: { type: RelatedVideo, label: 'Related Videos' }
      
  4. Event-Driven Updates

    • Listen for tied content changes via events (e.g., TiedContentAddedEvent):
      use Anh\TiedContentBundle\Event\TiedContentEvent;
      
      $eventDispatcher->addListener(TiedContentEvent::TIED_CONTENT_ADDED, function (TiedContentEvent $event) {
          // Log or trigger side effects
      });
      

Gotchas and Tips

Pitfalls

  1. Missing Interface Implementation

    • Forgetting to implement TiedContentInterface will break tied content functionality. Always check:
      class MyEntity implements TiedContentInterface { ... }
      
  2. Circular References

    • Bidirectional ties (e.g., Article ↔ Video) can cause infinite loops in serialization or queries. Use @ORM\BackedEnum or custom logic to break cycles.
  3. Doctrine ORM Quirks

    • If using Doctrine, ensure tied content collections are properly mapped:
      # src/Entity/Article.orm.yml
      Anh\TiedContentBundle\Model\TiedContent:
          collection: true
          mappedBy: null
          inversedBy: null
      
  4. Configuration Overrides

    • The bundle relies on YAML/XML config for relations. Overrides in config/packages/anh_tied_content.yaml may not load if the bundle isn’t properly registered.

Debugging Tips

  • Enable SQL Logging Add to .env:

    DOCTRINE_DDL_AUTO_CREATE_SCHEMA=true
    DOCTRINE_DDL_AUTO_COMPLETE_SCHEMA=true
    

    Check logs for tied content queries:

    bin/console debug:query "SELECT * FROM tied_content"
    
  • Dump Tied Content Use Symfony’s var dumper:

    dump($entity->getTiedContents('relation_name'));
    

Extension Points

  1. Custom Relation Types Extend the bundle’s relation system by creating a custom RelationType class and registering it in services:

    services:
        anh.tied_content.relation.type.custom:
            class: App\CustomRelationType
            tags: [anh.tied_content.relation_type]
    
  2. Validation Rules Add validation via constraints:

    use Symfony\Component\Validator\Constraints as Assert;
    
    class Article
    {
        /**
         * @Assert\Count(max="5")
         */
        private $tiedContents;
    }
    
  3. API Serialization Normalize tied content in API Platform/FOSRest:

    use Anh\TiedContentBundle\Serializer\TiedContentNormalizer;
    
    services:
        anh.tied_content.normalizer:
            class: TiedContentNormalizer
            tags: [serializer.normalizer]
    
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.
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels
wazza/laravel-db-encryption
hokny/laravel-generator
vonsogt/backup
jengo/queues
jeremykenedy/laravel-observability
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums