## Getting Started
### Minimal Setup
1. **Install via Composer**:
```bash
composer require nucleos/shariff-bundle
config/bundles.php:
return [
// ...
Nucleos\ShariffBundle\NucleosShariffBundle::class => ['all' => true],
];
config/packages/nucleos_shariff.yaml:
nucleos_shariff:
services: ['facebook', 'twitter', 'xing'] # Default services
theme: 'dark' # 'light' or 'dark'
url: 'https://your-site.com' # Base URL for shariff
{{ render(controller('NucleosShariffBundle:Shariff:render', {'services': ['facebook', 'twitter']})) }}
Dynamic Service Rendering:
{% if app.user.hasRole('ROLE_PREMIUM') %}
{{ render(controller('NucleosShariffBundle:Shariff:render', {
'services': ['facebook', 'linkedin'],
'theme': 'light'
})) }}
{% endif %}
Twig\Environment extensions).SonataAdmin Integration:
// src/Admin/YourAdmin.php
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('title')
->add('_action', 'actions', [
'actions' => [
'share' => [
'template' => '@NucleosShariff/share_button.html.twig',
'services' => ['twitter', 'facebook']
]
]
]);
}
templates/admin/YourAdmin/share_button.html.twig) to render shariff buttons.API-Driven Configuration:
// src/Service/ShariffConfigService.php
public function getShariffConfig(): array
{
return [
'services' => $this->configRepository->getEnabledServices(),
'theme' => $this->userPreferences->getTheme(),
];
}
{{ render(controller('NucleosShariffBundle:Shariff:render', app.shariffConfig)) }}
Event-Driven Extensions:
nucleos_shariff.build_config event to modify shariff configurations globally:
// src/EventListener/ShariffConfigListener.php
public function onBuildConfig(ShariffConfigEvent $event)
{
$event->setTheme('dark');
$event->addService('mastodon');
}
services.yaml:
services:
App\EventListener\ShariffConfigListener:
tags:
- { name: kernel.event_listener, event: nucleos_shariff.build_config }
Controller Resolution in Laravel:
// src/Twig/AppExtension.php
public function getShariffButtons(array $services, string $theme = 'dark'): string
{
$html = file_get_contents('https://your-site.com/shariff?' . http_build_query([
'services' => implode(',', $services),
'theme' => $theme,
]));
return new \Twig\Markup($html, 'UTF-8');
}
config/services.php:
Twig::getInstance()->addExtension(new \App\Twig\AppExtension());
Caching Static Assets:
config('cache.default')) does not aggressively cache the dynamic query strings (e.g., ?services=facebook,twitter). Use cache tags or versioned URLs:
{{ render(controller('NucleosShariffBundle:Shariff:render', {
'services': ['facebook'],
'cacheKey': 'shariff_facebook_v1'
})) }}
Archived Package Risks:
symfony/http-foundation:^5.4).Theme Inconsistencies:
theme option (light/dark) may not propagate correctly if shariff.js is loaded from a CDN. Override the CSS in your assets:
/* resources/assets/css/shariff-overrides.css */
.shariff-dark { --shariff-bg: #1a1a1a; } /* Customize dark theme */
Inspect Rendered HTML:
{{ render(controller(...)) }} in Twig. If empty, verify:
NucleosShariffBundle:Shariff:render).APP_DEBUG=true).Service-Specific Issues:
xing) fails to load, check:
Laravel-Specific Debugging:
dd() or dump() to inspect the bundle’s config:
dd(\Nucleos\ShariffBundle\DependencyInjection\Configuration::getConfigTreeBuilder());
Custom Services:
// src/Service/ExtendedShariffService.php
public function renderExtended(array $services): string
{
$services[] = 'custom_service';
return $this->render($services);
}
{{ app.extended_shariff.renderExtended(['facebook']) }}
Twig Filters:
// src/Twig/AppExtension.php
public function getFilters()
{
return [
new \Twig\TwigFilter('shariff_services', [$this, 'sanitizeServices']),
];
}
{{ ['facebook', 'twitter|']|shariff_services }}
Laravel Mix/Webpack:
// webpack.mix.js
mix.js('resources/js/shariff.js', 'public/js')
.copy('node_modules/shariff/dist/shariff.min.js', 'public/js/shariff.min.js');
<script src="{{ asset('js/shariff.min.js') }}"></script>
```markdown
## Additional Notes for Laravel Developers
- **Service Provider**: Register the bundle in `config/app.php` under `providers` (if not auto-discovered):
```php
Nucleos\ShariffBundle\NucleosShariffBundle::class,
routes/web.php:
Route::prefix('shariff')->group(function () {
// Proxy the Symfony controller or use the Twig extension
});
// app/Helpers/ShariffHelper.php
function shariffButtons(array $services): string
{
return app('twig')->render('shariff_
How can I help you explore Laravel packages today?