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:
45
Shared/Domain/Constants/VisibilityDefaults.php
Normal file
45
Shared/Domain/Constants/VisibilityDefaults.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Domain\Constants;
|
||||
|
||||
/**
|
||||
* Constantes de visibilidad por defecto para componentes
|
||||
*
|
||||
* Centraliza los valores por defecto para cumplir con DRY.
|
||||
* Usado por:
|
||||
* - EvaluatePageVisibilityUseCase (cuando no hay config en BD)
|
||||
* - MigratePageVisibilityService (para crear registros iniciales)
|
||||
*
|
||||
* @package ROITheme\Shared\Domain\Constants
|
||||
*/
|
||||
final class VisibilityDefaults
|
||||
{
|
||||
/**
|
||||
* Configuración de visibilidad por defecto para nuevos componentes
|
||||
*
|
||||
* - Home: SÍ mostrar (página principal)
|
||||
* - Posts: SÍ mostrar (artículos del blog)
|
||||
* - Pages: SÍ mostrar (páginas estáticas)
|
||||
* - Archives: NO mostrar (listados de categorías/tags)
|
||||
* - Search: NO mostrar (resultados de búsqueda)
|
||||
*/
|
||||
public const DEFAULT_VISIBILITY = [
|
||||
'show_on_home' => true,
|
||||
'show_on_posts' => true,
|
||||
'show_on_pages' => true,
|
||||
'show_on_archives' => false,
|
||||
'show_on_search' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* Lista de campos de visibilidad válidos
|
||||
*/
|
||||
public const VISIBILITY_FIELDS = [
|
||||
'show_on_home',
|
||||
'show_on_posts',
|
||||
'show_on_pages',
|
||||
'show_on_archives',
|
||||
'show_on_search',
|
||||
];
|
||||
}
|
||||
25
Shared/Domain/Contracts/PageTypeDetectorInterface.php
Normal file
25
Shared/Domain/Contracts/PageTypeDetectorInterface.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Domain\Contracts;
|
||||
|
||||
use ROITheme\Shared\Domain\ValueObjects\PageType;
|
||||
|
||||
/**
|
||||
* Contrato para detectar el tipo de página actual
|
||||
*
|
||||
* @package ROITheme\Shared\Domain\Contracts
|
||||
*/
|
||||
interface PageTypeDetectorInterface
|
||||
{
|
||||
/**
|
||||
* Detecta y retorna el tipo de página actual
|
||||
*/
|
||||
public function detect(): PageType;
|
||||
|
||||
public function isHome(): bool;
|
||||
public function isPost(): bool;
|
||||
public function isPage(): bool;
|
||||
public function isArchive(): bool;
|
||||
public function isSearch(): bool;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Domain\Contracts;
|
||||
|
||||
/**
|
||||
* Contrato para acceder a la configuración de visibilidad por página
|
||||
*
|
||||
* @package ROITheme\Shared\Domain\Contracts
|
||||
*/
|
||||
interface PageVisibilityRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Obtiene la configuración de visibilidad de un componente
|
||||
*
|
||||
* @param string $componentName Nombre del componente (kebab-case)
|
||||
* @return array<string, bool> Mapa de campo => habilitado
|
||||
*/
|
||||
public function getVisibilityConfig(string $componentName): array;
|
||||
|
||||
/**
|
||||
* Guarda la configuración de visibilidad de un componente
|
||||
*
|
||||
* @param string $componentName Nombre del componente
|
||||
* @param array<string, bool> $config Configuración a guardar
|
||||
*/
|
||||
public function saveVisibilityConfig(string $componentName, array $config): void;
|
||||
|
||||
/**
|
||||
* Verifica si existe configuración de visibilidad para un componente
|
||||
*/
|
||||
public function hasVisibilityConfig(string $componentName): bool;
|
||||
|
||||
/**
|
||||
* Obtiene lista de todos los componentes registrados
|
||||
*
|
||||
* @return array<string> Lista de nombres de componentes
|
||||
*/
|
||||
public function getAllComponentNames(): array;
|
||||
|
||||
/**
|
||||
* Crea configuración de visibilidad por defecto para un componente
|
||||
*
|
||||
* @param string $componentName Nombre del componente
|
||||
* @param array<string, bool> $defaults Valores por defecto
|
||||
*/
|
||||
public function createDefaultVisibility(string $componentName, array $defaults): void;
|
||||
}
|
||||
@@ -93,6 +93,9 @@ final readonly class ComponentConfiguration
|
||||
'widget_3', // Widget 3 del footer (menú)
|
||||
'newsletter', // Sección newsletter del footer
|
||||
'footer_bottom', // Pie del footer (copyright)
|
||||
|
||||
// Sistema de visibilidad por página
|
||||
'_page_visibility', // Visibilidad por tipo de página (home, posts, pages, archives, search)
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
90
Shared/Domain/ValueObjects/PageType.php
Normal file
90
Shared/Domain/ValueObjects/PageType.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ROITheme\Shared\Domain\ValueObjects;
|
||||
|
||||
/**
|
||||
* Value Object que representa los tipos de página válidos
|
||||
*
|
||||
* @package ROITheme\Shared\Domain\ValueObjects
|
||||
*/
|
||||
final class PageType
|
||||
{
|
||||
public const HOME = 'home';
|
||||
public const POST = 'post';
|
||||
public const PAGE = 'page';
|
||||
public const ARCHIVE = 'archive';
|
||||
public const SEARCH = 'search';
|
||||
public const UNKNOWN = 'unknown';
|
||||
|
||||
private const VALID_TYPES = [
|
||||
self::HOME,
|
||||
self::POST,
|
||||
self::PAGE,
|
||||
self::ARCHIVE,
|
||||
self::SEARCH,
|
||||
self::UNKNOWN,
|
||||
];
|
||||
|
||||
private function __construct(
|
||||
private readonly string $value
|
||||
) {}
|
||||
|
||||
public static function fromString(string $type): self
|
||||
{
|
||||
if (!in_array($type, self::VALID_TYPES, true)) {
|
||||
return new self(self::UNKNOWN);
|
||||
}
|
||||
return new self($type);
|
||||
}
|
||||
|
||||
public static function home(): self
|
||||
{
|
||||
return new self(self::HOME);
|
||||
}
|
||||
|
||||
public static function post(): self
|
||||
{
|
||||
return new self(self::POST);
|
||||
}
|
||||
|
||||
public static function page(): self
|
||||
{
|
||||
return new self(self::PAGE);
|
||||
}
|
||||
|
||||
public static function archive(): self
|
||||
{
|
||||
return new self(self::ARCHIVE);
|
||||
}
|
||||
|
||||
public static function search(): self
|
||||
{
|
||||
return new self(self::SEARCH);
|
||||
}
|
||||
|
||||
public function value(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return $this->value === $other->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retorna el nombre del campo de visibilidad correspondiente
|
||||
*/
|
||||
public function toVisibilityField(): string
|
||||
{
|
||||
return match ($this->value) {
|
||||
self::HOME => 'show_on_home',
|
||||
self::POST => 'show_on_posts',
|
||||
self::PAGE => 'show_on_pages',
|
||||
self::ARCHIVE => 'show_on_archives',
|
||||
self::SEARCH => 'show_on_search',
|
||||
default => 'show_on_posts',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user