Skip to content

Commit

Permalink
Semantic html
Browse files Browse the repository at this point in the history
* wrap main_above and main_below in main
* change #main to div
* write migration
  • Loading branch information
zoglo committed Oct 30, 2024
1 parent dd4fd10 commit e1084c7
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 34 deletions.
7 changes: 7 additions & 0 deletions config/migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ services:
- '@contao.framework'
tags:
- { name: contao.migration, priority: 0 }

ContaoThemeManager\Core\Migration\Version220\CustomLayoutSectionMigration:
arguments:
- '@database_connection'
- '@contao.framework'
tags:
- { name: contao.migration, priority: 0 }
70 changes: 37 additions & 33 deletions contao/templates/frontend/fe_page.html5
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,46 @@
<?php $this->sections('before'); ?>

<?php $this->block('container'); ?>
<?php if ($this->main || $this->left || $this->right): ?>
<div id="container">
<div class="inside">

<?php $this->block('main'); ?>
<main id="main">
<div class="inside">
<?= $this->main ?>
</div>
<?php $this->sections('main'); ?>
</main>
<?php $this->endblock(); ?>

<?php $this->block('left'); ?>
<?php if ($this->left): ?>
<aside id="left" class="grid">
<div class="inside">
<?= $this->left ?>
</div>
</aside>
<?php endif; ?>
<?php $this->endblock(); ?>

<?php $this->block('right'); ?>
<?php if ($this->right): ?>
<aside id="right" class="grid">
<main id="main-wrapper">
<?php $this->section('main-above'); ?>
<?php if ($this->main || $this->left || $this->right): ?>
<div id="container">
<div class="inside">

<?php $this->block('main'); ?>
<div id="main">
<div class="inside">
<?= $this->right ?>
<?= $this->main ?>
</div>
</aside>
<?php endif; ?>
<?php $this->endblock(); ?>

<?php $this->sections('main'); ?>
</div>
<?php $this->endblock(); ?>

<?php $this->block('left'); ?>
<?php if ($this->left): ?>
<aside id="left" class="grid">
<div class="inside">
<?= $this->left ?>
</div>
</aside>
<?php endif; ?>
<?php $this->endblock(); ?>

<?php $this->block('right'); ?>
<?php if ($this->right): ?>
<aside id="right" class="grid">
<div class="inside">
<?= $this->right ?>
</div>
</aside>
<?php endif; ?>
<?php $this->endblock(); ?>

</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<?php $this->section('main-below'); ?>
</main>
<?php $this->endblock(); ?>

<?php $this->sections('after'); ?>
Expand Down
2 changes: 1 addition & 1 deletion public/framework/scss/ctm_layout/_article-spacing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $spacings-list-bp: (
);

// Add default bottom-padding to #main articles
main {
#main {
.mod_article:nth-last-child(n+2) { --mpb:#{$article-main-spacing-bottom}; }
.article_inside { padding-bottom: var(--mpb,0); }
}
Expand Down
86 changes: 86 additions & 0 deletions src/Migration/Version220/CustomLayoutSectionMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/*
* This file is part of Contao ThemeManager Core.
*
* (c) https://www.oveleon.de/
*/

namespace ContaoThemeManager\Core\Migration\Version220;

use Contao\CoreBundle\Migration\AbstractMigration;
use Contao\CoreBundle\Migration\MigrationResult;
use Contao\StringUtil;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;

class CustomLayoutSectionMigration extends AbstractMigration
{
public function __construct(private readonly Connection $connection)
{
}

/**
* @throws Exception
*/
public function shouldRun(): bool
{
$schemaManager = $this->connection->createSchemaManager();

if (!$schemaManager->tablesExist('tl_layout'))
{
return false;
}

$columns = $schemaManager->listTableColumns('tl_layout');

if (!isset($columns['sections']))
{
return false;
}

$test = $this->connection->fetchOne("SELECT TRUE FROM tl_layout WHERE sections LIKE '%s:2:\"id\";s:10:\"main-above\";s:8:\"template\";s:13:\"block_section\";s:8:\"position\";s:6:\"before\";%' OR sections LIKE '%s:2:\"id\";s:10:\"main-below\";s:8:\"template\";s:13:\"block_section\";s:8:\"position\";s:5:\"after\";%' LIMIT 1");

if (false !== $test)
{
return true;
}

return false;
}

/**
* @throws Exception
*/
public function run(): MigrationResult
{
$values = $this->connection->fetchAllKeyValue("SELECT id, sections FROM tl_layout WHERE sections LIKE '%s:2:\"id\";s:10:\"main-above\";s:8:\"template\";s:13:\"block_section\";s:8:\"position\";s:6:\"before\";%' OR sections LIKE '%s:2:\"id\";s:10:\"main-below\";s:8:\"template\";s:13:\"block_section\";s:8:\"position\";s:5:\"after\";%'");

foreach ($values as $id => $value)
{
$blnUpdate = false;

$sections = StringUtil::deserialize($value, true);

foreach ($sections as &$section)
{
if (!isset($section['id']) || !in_array($section['id'], ['main-above', 'main-below']))
{
continue;
}

$section['position'] = 'manual';
$blnUpdate = true;
}

if ($blnUpdate)
{
$this->connection->update('tl_layout', ['sections' => serialize($sections)], ['id' => (int) $id]);
}
}

return $this->createResult(true);
}
}

0 comments on commit e1084c7

Please sign in to comment.