feat(exclusions): Integrate exclusion UI in CtaBoxSidebar component
- Add ExclusionFormPartial to CtaBoxSidebarFormBuilder - Add _exclusions fields to CtaBoxSidebarFieldMapper with types - Update AdminAjaxHandler to process json_array types via ExclusionFieldProcessor - Enqueue exclusion-toggle.js in AdminAssetEnqueuer The exclusion UI now appears in CTA Box Sidebar visibility section, allowing admins to exclude component from specific categories, post IDs, or URL patterns. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,12 @@ final class CtaBoxSidebarFieldMapper implements FieldMapperInterface
|
|||||||
'ctaVisibilityArchives' => ['group' => '_page_visibility', 'attribute' => 'show_on_archives'],
|
'ctaVisibilityArchives' => ['group' => '_page_visibility', 'attribute' => 'show_on_archives'],
|
||||||
'ctaVisibilitySearch' => ['group' => '_page_visibility', 'attribute' => 'show_on_search'],
|
'ctaVisibilitySearch' => ['group' => '_page_visibility', 'attribute' => 'show_on_search'],
|
||||||
|
|
||||||
|
// Exclusions (grupo especial _exclusions - Plan 99.11)
|
||||||
|
'ctaExclusionsEnabled' => ['group' => '_exclusions', 'attribute' => 'exclusions_enabled'],
|
||||||
|
'ctaExcludeCategories' => ['group' => '_exclusions', 'attribute' => 'exclude_categories', 'type' => 'json_array'],
|
||||||
|
'ctaExcludePostIds' => ['group' => '_exclusions', 'attribute' => 'exclude_post_ids', 'type' => 'json_array_int'],
|
||||||
|
'ctaExcludeUrlPatterns' => ['group' => '_exclusions', 'attribute' => 'exclude_url_patterns', 'type' => 'json_array_lines'],
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
'ctaTitle' => ['group' => 'content', 'attribute' => 'title'],
|
'ctaTitle' => ['group' => 'content', 'attribute' => 'title'],
|
||||||
'ctaDescription' => ['group' => 'content', 'attribute' => 'description'],
|
'ctaDescription' => ['group' => 'content', 'attribute' => 'description'],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
namespace ROITheme\Admin\CtaBoxSidebar\Infrastructure\Ui;
|
namespace ROITheme\Admin\CtaBoxSidebar\Infrastructure\Ui;
|
||||||
|
|
||||||
use ROITheme\Admin\Infrastructure\Ui\AdminDashboardRenderer;
|
use ROITheme\Admin\Infrastructure\Ui\AdminDashboardRenderer;
|
||||||
|
use ROITheme\Admin\Shared\Infrastructure\Ui\ExclusionFormPartial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FormBuilder para el CTA Box Sidebar
|
* FormBuilder para el CTA Box Sidebar
|
||||||
@@ -130,6 +131,13 @@ final class CtaBoxSidebarFormBuilder
|
|||||||
$html .= ' </div>';
|
$html .= ' </div>';
|
||||||
$html .= ' </div>';
|
$html .= ' </div>';
|
||||||
|
|
||||||
|
// =============================================
|
||||||
|
// Reglas de exclusion avanzadas
|
||||||
|
// Grupo especial: _exclusions (Plan 99.11)
|
||||||
|
// =============================================
|
||||||
|
$exclusionPartial = new ExclusionFormPartial($this->renderer);
|
||||||
|
$html .= $exclusionPartial->render($componentId, 'cta');
|
||||||
|
|
||||||
$html .= ' </div>';
|
$html .= ' </div>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,15 @@ final class AdminAssetEnqueuer
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Script de toggle para exclusiones (Plan 99.11)
|
||||||
|
wp_enqueue_script(
|
||||||
|
'roi-exclusion-toggle',
|
||||||
|
$this->themeUri . '/Admin/Shared/Infrastructure/Ui/Assets/Js/exclusion-toggle.js',
|
||||||
|
['roi-admin-dashboard'],
|
||||||
|
filemtime(get_template_directory() . '/Admin/Shared/Infrastructure/Ui/Assets/Js/exclusion-toggle.js'),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
// Pasar variables al JavaScript
|
// Pasar variables al JavaScript
|
||||||
wp_localize_script(
|
wp_localize_script(
|
||||||
'roi-admin-dashboard',
|
'roi-admin-dashboard',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace ROITheme\Admin\Shared\Infrastructure\Api\WordPress;
|
|||||||
|
|
||||||
use ROITheme\Shared\Application\UseCases\SaveComponentSettings\SaveComponentSettingsUseCase;
|
use ROITheme\Shared\Application\UseCases\SaveComponentSettings\SaveComponentSettingsUseCase;
|
||||||
use ROITheme\Admin\Shared\Infrastructure\FieldMapping\FieldMapperRegistry;
|
use ROITheme\Admin\Shared\Infrastructure\FieldMapping\FieldMapperRegistry;
|
||||||
|
use ROITheme\Admin\Shared\Infrastructure\Services\ExclusionFieldProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler para peticiones AJAX del panel de administracion
|
* Handler para peticiones AJAX del panel de administracion
|
||||||
@@ -73,10 +74,16 @@ final class AdminAjaxHandler
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapea settings de field IDs a grupos/atributos
|
* Mapea settings de field IDs a grupos/atributos
|
||||||
|
*
|
||||||
|
* Soporta tipos especiales para campos de exclusion:
|
||||||
|
* - json_array: Convierte "a, b, c" a ["a", "b", "c"]
|
||||||
|
* - json_array_int: Convierte "1, 2, 3" a [1, 2, 3]
|
||||||
|
* - json_array_lines: Convierte lineas a array
|
||||||
*/
|
*/
|
||||||
private function mapSettings(array $settings, array $fieldMapping): array
|
private function mapSettings(array $settings, array $fieldMapping): array
|
||||||
{
|
{
|
||||||
$mappedSettings = [];
|
$mappedSettings = [];
|
||||||
|
$fieldProcessor = new ExclusionFieldProcessor();
|
||||||
|
|
||||||
foreach ($settings as $fieldId => $value) {
|
foreach ($settings as $fieldId => $value) {
|
||||||
if (!isset($fieldMapping[$fieldId])) {
|
if (!isset($fieldMapping[$fieldId])) {
|
||||||
@@ -86,11 +93,17 @@ final class AdminAjaxHandler
|
|||||||
$mapping = $fieldMapping[$fieldId];
|
$mapping = $fieldMapping[$fieldId];
|
||||||
$groupName = $mapping['group'];
|
$groupName = $mapping['group'];
|
||||||
$attributeName = $mapping['attribute'];
|
$attributeName = $mapping['attribute'];
|
||||||
|
$type = $mapping['type'] ?? null;
|
||||||
|
|
||||||
if (!isset($mappedSettings[$groupName])) {
|
if (!isset($mappedSettings[$groupName])) {
|
||||||
$mappedSettings[$groupName] = [];
|
$mappedSettings[$groupName] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Procesar valor segun tipo
|
||||||
|
if ($type !== null && is_string($value)) {
|
||||||
|
$value = $fieldProcessor->process($value, $type);
|
||||||
|
}
|
||||||
|
|
||||||
$mappedSettings[$groupName][$attributeName] = $value;
|
$mappedSettings[$groupName][$attributeName] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user