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

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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
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