Installation
composer require c975l/social-bundle
Add to config/bundles.php:
return [
// ...
C975L\SocialBundle\C975LSocialBundle::class => ['all' => true],
];
Database Migration
Run migrations to create the social_links table (if using Doctrine):
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case Display the social links block in a Twig template:
{{ render_block('social_links') }}
Or use the share buttons:
{{ share_buttons() }}
/admin/social_links). No need to integrate into existing block collections.social_links_display block in any page’s block flow:
{{ render_block('social_links_display') }}
config/packages/c975l_social.yaml:
c975l_social:
enable_share_buttons: true
networks: [twitter, facebook, linkedin] # Customize networks
style: flat # Options: flat, badge, monochrome
{# Auto-render on all pages if enabled #}
{{ include('C975LSocialBundle:share_buttons.html.twig') }}
{# Manual override with custom URL #}
{{ share_buttons('https://example.com/my-page') }}
networks config or extend the SocialNetwork enum (if available) in your bundle.icon key in the social_links table to reference custom SVG/FontAwesome icons.C975LSocialBundleEvents::POST_SCHEDULED to integrate with third-party APIs (e.g., Buffer, Hootsuite) when the feature is added.Service Registration:
Register the bundle’s services in config/services.php or use Laravel’s package auto-discovery:
composer require laravel/package-autoload
Twig Integration: Ensure Twig is configured to auto-reload templates:
// config/view.php
'compiled' => env('APP_DEBUG') ? false : true,
EasyAdmin Compatibility:
If using EasyAdmin, ensure your EasyAdminBundle config includes:
easy_admin:
entities:
C975L\SocialBundle\Entity\SocialLink:
class: C975L\SocialBundle\Entity\SocialLink
label: 'Social Links'
Block System Integration:
For Laravel’s block systems (e.g., spatie/laravel-blocks), map the social_links_display block to your block registry:
// AppServiceProvider@boot
Block::macro('socialLinks', function () {
return Block::create('social_links_display')
->setTemplate('C975LSocialBundle::blocks/social_links_display');
});
Database Schema Assumptions:
social_links table. If using Laravel’s migrations, manually create it or extend the bundle’s migrations.config/packages/c975l_social.yaml:
c975l_social:
migration_path: 'vendor/c975l/social-bundle/migrations'
EasyAdmin Dependency:
/admin/social_links route will 404.c975l_social:
enable_admin: false
Twig Function Conflicts:
share_buttons() function may conflict with existing Twig extensions.// config/services.php
Twig\Environment::class => fn($container) => $container->get('twig')->addFunction(
new \Twig\TwigFunction('custom_share_buttons', [$container->get('c975l_social.share_button_service'), 'render'])
);
Caching Issues:
php artisan cache:clear
php artisan view:clear
Log Social Link Queries:
Enable Doctrine logging to debug social_links queries:
# config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
profiling: true
Check Block Rendering: Verify the block is registered in your block system:
php artisan block:list
Network-Specific Errors:
networks config for typos or unsupported networks.dd() in the ShareButtonService (if extendable) to inspect the networks array.Custom Social Networks:
Extend the SocialNetwork enum (if available) or override the getNetworks() method in the service:
// src/Service/CustomSocialService.php
use C975L\SocialBundle\Service\ShareButtonService;
class CustomSocialService extends ShareButtonService
{
public function getNetworks(): array
{
return array_merge(parent::getNetworks(), ['custom_network']);
}
}
Register the service in config/services.php:
services:
C975L\SocialBundle\Service\ShareButtonService:
alias: App\Service\CustomSocialService
Block Template Overrides:
Override Twig templates in resources/views/override/C975LSocialBundle/:
resources/
views/
override/
C975LSocialBundle/
blocks/
social_links.html.twig
Scheduled Posting Hooks: Listen for future events (once implemented):
// EventSubscriber
public static function getSubscribedEvents()
{
return [
C975LSocialBundleEvents::POST_SCHEDULED => 'onPostScheduled',
];
}
public function onPostScheduled(PostScheduledEvent $event)
{
// Integrate with your API (e.g., Buffer)
}
Icon Customization:
Add custom icons by extending the SocialLink entity or using CSS:
/* resources/css/app.css */
.social-link-icon.custom-network::before {
content: "\f123"; /* FontAwesome icon */
}
How can I help you explore Laravel packages today?