bupychuk/sensi-yaml-gui-bundle
Installation
composer require bupychuk/sensi-yaml-gui-bundle
Update AppKernel.php to register the bundle:
new Sensi\Bundle\YamlGuiBundle\SensiYamlGuiBundle(),
Routing
Add to app/config/routing.yml:
sensi_yaml_gui:
resource: "@SensiYamlGuiBundle/Resources/config/routing.yml"
prefix: /yamlgui
Configuration
Create app/config/yamlgui.yml:
sensi_yaml_gui:
config_root_dir: "%kernel.root_dir%/config/yamlgui/"
managed_files:
"demo.yml": { title: "Demo Config" }
Include it in config.yml:
imports:
- { resource: yamlgui.yml }
First Use Case
Place a YAML file (e.g., demo.yml) in config/yamlgui/ and access /yamlgui to edit it via a web form.
Standalone Usage
sonata_admin_modus: false in yamlgui.yml./yamlgui for a lightweight form-based YAML editor.SonataAdmin Integration
sonata_admin_modus: true to embed the editor in Sonata’s dashboard.SensiYamlGuiBundle::default.html.twig.File Management
managed_files in yamlgui.yml with new YAML paths and titles.config_root_dir is writable by the web server (e.g., chmod -R 775 config/yamlgui).Validation
{{ dump(yamlgui_config) }} in templates to debug parsed YAML.sensi.yaml_gui.save event to trigger actions post-save:
// src/Acme/EventListener/YamlGuiListener.php
public function onYamlSave(YamlGuiEvent $event) {
$file = $event->getFile();
// Reload config or trigger cache clear
}
File Permissions
config_root_dir lacks write access.chmod -R 775 config/yamlgui and ensure the web server user (e.g., www-data) owns the directory.YAML Parsing Errors
APP_DEBUG=true).Caching Quirks
yamlgui.yml may not reflect immediately due to Symfony’s config cache.php bin/console cache:clear
SonataAdmin Conflicts
sonata_admin_modus: true but SonataAdmin isn’t installed.{% extends 'SensiYamlGuiBundle::default.html.twig' %}
{% block body %}
{{ dump(yamlgui_config) }}
{{ parent() }}
{% endblock %}
public function onYamlSave(YamlGuiEvent $event) {
\Log::info('Saved file:', [$event->getFile()]);
}
Custom Templates
Override the default template at app/Resources/SensiYamlGuiBundle/views/default.html.twig.
Form Type Extensions Extend the base form type to add custom fields or validation:
// src/Acme/SensiYamlGui/Extension/YamlGuiExtension.php
public function loadExtension(YamlGuiExtension $extension, FormBuilderInterface $builder, array $options) {
$builder->add('custom_field', TextType::class);
}
Post-Save Logic
Use the sensi.yaml_gui.save event to integrate with other systems (e.g., database sync):
# config/services.yml
services:
acme.yaml_gui_listener:
tag: kernel.event_listener
class: Acme\EventListener\YamlGuiListener
arguments: ['@some_service']
calls:
- [setContainer, ['@service_container']]
tags:
- { name: kernel.event_listener, event: sensi.yaml_gui.save, method: onYamlSave }
Security Hardening Add a voter to restrict access to sensitive configs:
public function supportsAttribute($attribute) {
return $attribute === 'yaml_edit';
}
public function vote(TokenInterface $token, $object, array $attributes) {
return $token->hasRole('ROLE_YAML_ADMIN') ? AccessDecisionInterface::ACCESS_GRANTED : AccessDecisionInterface::ACCESS_DENIED;
}
How can I help you explore Laravel packages today?