Installation
composer require anh/tied-content-bundle
Add to config/bundles.php (Symfony):
Anh\TiedContentBundle\AnhTiedContentBundle::class => ['all' => true],
First Use Case
Article and RelatedVideo).use Anh\TiedContentBundle\Model\TiedContentInterface;
// Assume $article is an Article entity with TiedContentInterface
$article->addTiedContent($relatedVideo, 'related_videos');
$article->save();
Key Files to Explore
src/Resources/config/services.xml (Symfony DI config)src/Model/TiedContentInterface.php (Core interface)src/DependencyInjection/ (Bundle configuration)Defining Tied Content Relationships
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] ?? [];
}
}
Querying Tied Content
$article = $articleRepo->find($id);
$relatedVideos = $article->getTiedContents('related_videos');
Admin Integration (Symfony Admin Bundle)
# config/admin.yml
anh_content:
tied_content:
Article:
related_videos: { type: RelatedVideo, label: 'Related Videos' }
Event-Driven Updates
TiedContentAddedEvent):
use Anh\TiedContentBundle\Event\TiedContentEvent;
$eventDispatcher->addListener(TiedContentEvent::TIED_CONTENT_ADDED, function (TiedContentEvent $event) {
// Log or trigger side effects
});
Missing Interface Implementation
TiedContentInterface will break tied content functionality. Always check:
class MyEntity implements TiedContentInterface { ... }
Circular References
Article ↔ Video) can cause infinite loops in serialization or queries. Use @ORM\BackedEnum or custom logic to break cycles.Doctrine ORM Quirks
# src/Entity/Article.orm.yml
Anh\TiedContentBundle\Model\TiedContent:
collection: true
mappedBy: null
inversedBy: null
Configuration Overrides
config/packages/anh_tied_content.yaml may not load if the bundle isn’t properly registered.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'));
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]
Validation Rules Add validation via constraints:
use Symfony\Component\Validator\Constraints as Assert;
class Article
{
/**
* @Assert\Count(max="5")
*/
private $tiedContents;
}
API Serialization Normalize tied content in API Platform/FOSRest:
use Anh\TiedContentBundle\Serializer\TiedContentNormalizer;
services:
anh.tied_content.normalizer:
class: TiedContentNormalizer
tags: [serializer.normalizer]
How can I help you explore Laravel packages today?