feat(visibility): sistema de visibilidad por tipo de página
- Añadir PageVisibility use case y repositorio - Implementar PageTypeDetector para detectar home/single/page/archive - Actualizar FieldMappers con soporte show_on_[page_type] - Extender FormBuilders con UI de visibilidad por página - Refactorizar Renderers para evaluar visibilidad dinámica - Limpiar schemas removiendo campos de visibilidad legacy - Añadir MigrationCommand para migrar configuraciones existentes - Implementar adsense-loader.js para carga lazy de ads - Actualizar front-page.php con nueva estructura - Extender DIContainer con nuevos servicios 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Infrastructure\Services;
|
||||
|
||||
use ROITheme\Shared\Domain\Contracts\PageVisibilityRepositoryInterface;
|
||||
use ROITheme\Shared\Domain\Constants\VisibilityDefaults;
|
||||
|
||||
/**
|
||||
* Servicio para migrar configuración de visibilidad inicial
|
||||
*
|
||||
* @package ROITheme\Shared\Infrastructure\Services
|
||||
*/
|
||||
final class MigratePageVisibilityService
|
||||
{
|
||||
// NOTA: Usa VisibilityDefaults::DEFAULT_VISIBILITY para cumplir DRY
|
||||
|
||||
public function __construct(
|
||||
private readonly PageVisibilityRepositoryInterface $visibilityRepository
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Ejecuta la migración para todos los componentes
|
||||
*
|
||||
* @return array{created: int, skipped: int}
|
||||
*/
|
||||
public function migrate(): array
|
||||
{
|
||||
$created = 0;
|
||||
$skipped = 0;
|
||||
|
||||
$components = $this->visibilityRepository->getAllComponentNames();
|
||||
|
||||
foreach ($components as $componentName) {
|
||||
if ($this->visibilityRepository->hasVisibilityConfig($componentName)) {
|
||||
$skipped++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Usar constante compartida (DRY)
|
||||
$this->visibilityRepository->createDefaultVisibility(
|
||||
$componentName,
|
||||
VisibilityDefaults::DEFAULT_VISIBILITY
|
||||
);
|
||||
$created++;
|
||||
}
|
||||
|
||||
return [
|
||||
'created' => $created,
|
||||
'skipped' => $skipped,
|
||||
];
|
||||
}
|
||||
}
|
||||
39
Shared/Infrastructure/Services/PageVisibilityHelper.php
Normal file
39
Shared/Infrastructure/Services/PageVisibilityHelper.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Infrastructure\Services;
|
||||
|
||||
use ROITheme\Shared\Infrastructure\Di\DIContainer;
|
||||
|
||||
/**
|
||||
* Facade/Helper para evaluar visibilidad de componentes
|
||||
*
|
||||
* PROPÓSITO:
|
||||
* Permite que los Renderers existentes evalúen visibilidad sin modificar sus constructores.
|
||||
* Actúa como un Service Locator limitado a este único propósito.
|
||||
*
|
||||
* USO EN RENDERERS:
|
||||
* ```php
|
||||
* if (!PageVisibilityHelper::shouldShow('cta-box-sidebar')) {
|
||||
* return '';
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @package ROITheme\Shared\Infrastructure\Services
|
||||
*/
|
||||
final class PageVisibilityHelper
|
||||
{
|
||||
/**
|
||||
* Evalúa si un componente debe mostrarse en la página actual
|
||||
*
|
||||
* @param string $componentName Nombre del componente (kebab-case)
|
||||
* @return bool True si debe mostrarse
|
||||
*/
|
||||
public static function shouldShow(string $componentName): bool
|
||||
{
|
||||
$container = DIContainer::getInstance();
|
||||
$useCase = $container->getEvaluatePageVisibilityUseCase();
|
||||
|
||||
return $useCase->execute($componentName);
|
||||
}
|
||||
}
|
||||
65
Shared/Infrastructure/Services/WordPressPageTypeDetector.php
Normal file
65
Shared/Infrastructure/Services/WordPressPageTypeDetector.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Infrastructure\Services;
|
||||
|
||||
use ROITheme\Shared\Domain\Contracts\PageTypeDetectorInterface;
|
||||
use ROITheme\Shared\Domain\ValueObjects\PageType;
|
||||
|
||||
/**
|
||||
* Implementación WordPress del detector de tipo de página
|
||||
*
|
||||
* @package ROITheme\Shared\Infrastructure\Services
|
||||
*/
|
||||
final class WordPressPageTypeDetector implements PageTypeDetectorInterface
|
||||
{
|
||||
public function detect(): PageType
|
||||
{
|
||||
if ($this->isHome()) {
|
||||
return PageType::home();
|
||||
}
|
||||
|
||||
if ($this->isPost()) {
|
||||
return PageType::post();
|
||||
}
|
||||
|
||||
if ($this->isPage()) {
|
||||
return PageType::page();
|
||||
}
|
||||
|
||||
if ($this->isSearch()) {
|
||||
return PageType::search();
|
||||
}
|
||||
|
||||
if ($this->isArchive()) {
|
||||
return PageType::archive();
|
||||
}
|
||||
|
||||
return PageType::fromString(PageType::UNKNOWN);
|
||||
}
|
||||
|
||||
public function isHome(): bool
|
||||
{
|
||||
return is_front_page();
|
||||
}
|
||||
|
||||
public function isPost(): bool
|
||||
{
|
||||
return is_single() && !is_front_page();
|
||||
}
|
||||
|
||||
public function isPage(): bool
|
||||
{
|
||||
return is_page() && !is_front_page();
|
||||
}
|
||||
|
||||
public function isArchive(): bool
|
||||
{
|
||||
return is_archive();
|
||||
}
|
||||
|
||||
public function isSearch(): bool
|
||||
{
|
||||
return is_search();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user