Browse Source

5.2 Convert blocks in footer to Bootstrap panels.

Frederic G. MARAND 8 years ago
parent
commit
8fc4b2371a
9 changed files with 292 additions and 14 deletions
  1. 9 0
      css/theme/evidence.css
  2. 147 0
      docs/plan.html
  3. 6 6
      dr821.info.yml
  4. 8 2
      dr821.libraries.yml
  5. 75 0
      dr821.theme
  6. 16 0
      js/panelize.js
  7. 7 0
      module/dr821m.info.yml
  8. 21 0
      module/dr821m.module
  9. 3 6
      templates/layout/page.html.twig

+ 9 - 0
css/theme/evidence.css

@@ -6,3 +6,12 @@
 .container-fluid {
   border: thin solid mediumpurple;
 }
+
+.panel-body {
+  min-height: 3em;
+}
+
+ol.panel-body,
+ul.panel-body {
+  margin-bottom: 0;
+}

+ 147 - 0
docs/plan.html

@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <title>Title</title>
+</head>
+<body>
+<ul>
+  <li>Qu’est-ce qu’un thème ?
+    <ul>
+      <li>Thèmes, templates, moteurs et hooks : Twig, Nyan</li>
+      <li>Place des framework CSS</li>
+      <li>Autres composants : CSS, JS, images, styles d’image, breakpoints…</li>
+      <li>Prétraitements</li>
+      <li>Thèmes de front et de back</li>
+      <li>Régions et blocs</li>
+      <li>De la maquette au thème</li>
+    </ul>
+  </li>
+  <li>Le modèle d’héritage et les thèmes
+    <ul>
+      <li>Thème de base et sous-thèmes
+        <ul>
+          <li>Les thèmes D8 Core : Stark, Stable, Classy, Seven, Bartik</li>
+          <li>Les thèmes de base contrib : Bootstrap, Zurb Foundation, Omega</li>
+        </ul>
+      </li>
+      <li>Héritage des assets
+        <ul>
+          <li>libraries</li>
+          <li>libraries-extend</li>
+          <li>libraries-override</li>
+        </ul>
+      </li>
+      <li>Héritage de templates</li>
+      <li>Héritage CSS
+        <ul>
+          <li>Cascade CSS</li>
+          <li>SMACSS 1: concepts</li>
+          <li>SMACSS 2: architecture CSS</li>
+        </ul>
+      </li>
+      <li>Héritage et compilateurs CSS</li>
+    </ul>
+  </li>
+  <li>Le contenu d’un thème
+    <ul>
+      <li>Thème minimal</li>
+      <li>Exercice: thème nu</li>
+      <li>Ajout d'un framework CSS: Bootstrap</li>
+      <li>Exercice: observer Bootstrap</li>
+
+
+
+
+
+      <li>configuration: styles d’image</li>
+      <li>la hiérarchie des templates</li>
+      <li>dossiers</li>
+      <li>ajouter du CSS – libraries</li>
+      <li>ajouter du JS – libraries</li>
+      <li>Exercice : créer un thème affichant un texte fixe</li>
+    </ul>
+  </li>
+  <li>Twig 1 : mécanismes de base
+    <ul>
+      <li>Le format Twig</li>
+      <li>Variables</li>
+      <li>Littéraux, interpolation de chaînes</li>
+      <li>Expressions</li>
+      <li>Fonctions et arguments (nommés)</li>
+      <li>Opérateurs mathématiques, logiques, binaires, et comparateurs</li>
+      <li>Structures de contrôle</li>
+      <li>Commentaires</li>
+      <li><em>Exercice : afficher le nom de l’utilisateur connecté</em></li>
+    </ul>
+  </li>
+  <li>
+    <ul>
+      <li>Twig 2 : intégration Twig/D8</li>
+      <li>Développer avec Twig :
+        <ul>
+          <li>development.services.yml</li>
+          <li>debug mode</li>
+          <li>Caching vs refresh</li>
+        </ul>
+      </li>
+      <li>Filtres Twig D8
+        <ul>
+          <li>traduction</li>
+          <li>localisation</li>
+          <li>échappement</li>
+          <li>traitement des tableaux d’affichage</li>
+        </ul>
+      </li>
+      <li>Fonctions Twig D8 : URLs de contenu, assets, bibliothèques</li>
+      <li>Ajout de code JS</li>
+      <li>Show/hide() pour la hiérarchie des tableaux d’affichage</li>
+      <li><em>Exercice long: construire un thème utilisable</em></li>
+    </ul>
+  </li>
+  <li>-- Fin de la première journée --</li>
+  <li>Twig 3 : mécanisme évolués
+    <ul>
+      <li>Contrôle de l’espacement</li>
+      <li>Liens entre templates : include</li>
+      <li>Aparté : block/extends, use, embed</li>
+      <li>Sécurité : échappement</li>
+      <li>Macros</li>
+      <li><em>Quiz</em></li>
+    </ul>
+  </li>
+  <li>Création du markup et styling
+    <ul>
+      <li>HTML5 et D8 : éléments sémantiques</li>
+      <li>Accessibilité et web sémantique : RDF, rôles ARIA</li>
+      <li>Accessibilité : annonces ARIA</li>
+      <li>Accessibilité : gérer le clavier avec le tabbing manager, devel_ally</li>
+      <li>CSS : gestion i18n LTR/RTL</li>
+      <li>Conventions de nommage BEM, SMACSS et D8</li>
+      <li>Compilation CSS : LESS, SASS, Stylus</li>
+      <li>Impact de l’agrégation Drupal sur les styles</li>
+      <li><em>Quiz</em></li>
+    </ul>
+  </li>
+  <li>Conception de thèmes responsive
+    <ul>
+      <li>Media queries</li>
+      <li>Déboguage des queries avec les outils de développement Chrome</li>
+      <li>D8 : breakpoints, groupes de breakpoints et multiplicateurs</li>
+      <li>Intégration aux modules spécifiques</li>
+      <li><em>Exercice : thémer une vue Views responsive sur 2 formats</em></li>
+    </ul>
+  </li>
+  <li>Theming D8 Avancé
+    <ul>
+      <li>Theming Javascript : Drupal.theme()</li>
+      <li>Définir des réglages pour son thème</li>
+      <li>Définir un moteur de thème : exemple Nyan cat</li>
+      <li>Définir de nouvelles fonctionnalités Twig: filtres, tags, fonctions, tests</li>
+      <li>Exercice : définir un paramètre pour son thème</li>
+    </ul>
+  </li>
+  <li><em>Exercice final long : thème responsive basé sur Bootstrap</em></li>
+</ul>
+</body>
+</html>

+ 6 - 6
dr821.info.yml

@@ -2,16 +2,19 @@ name: DR-821
 type: theme
 description: 'Theme OSInet Formation DR-821'
 core: 8.x
+package: 'OSInet Formation'
 # Pas de base theme -> stable
 
 libraries:
+  # An alternative JS solution to panelize blocks.
+  #- dr821/panelize
   # Activer l'une des deux versions, pas les deux.
 
   # Version production, minifiée
-  # - dr821/bootstrap
+  - dr821/bootstrap
 
   # Version développement/déboguage, non minifiée
-  - dr821/bootstrap-dev
+  #- dr821/bootstrap-dev
 
 regions:
   header: Header
@@ -27,10 +30,7 @@ regions:
   featured_bottom_first: 'Featured bottom first'
   featured_bottom_second: 'Featured bottom second'
   featured_bottom_third: 'Featured bottom third'
-  footer_first: 'Footer first'
-  footer_second: 'Footer second'
-  footer_third: 'Footer third'
-  footer_fourth: 'Footer fourth'
+  footer: 'Footer'
   legalese_first: 'Legalese first'
   legalese_second: 'Legalese second'
 

+ 8 - 2
dr821.libraries.yml

@@ -3,6 +3,12 @@ evidence:
     theme:
       css/theme/evidence.css: {}
 
+panelize:
+  js:
+    js/panelize.js: {}
+  dependencies:
+    - core/jquery
+
 bootstrap:
   css:
     layout:
@@ -11,8 +17,8 @@ bootstrap:
       node_modules/bootstrap/dist/css/bootstrap-theme.min.css: {}
   js:
     node_modules/bootstrap/dist/js/bootstrap.min.js: {}
-    dependencies:
-      - core/jquery
+  dependencies:
+    - core/jquery
 
 bootstrap-dev:
   css:

+ 75 - 0
dr821.theme

@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * Implements hook_block_view_alter().
+ *
+ * Convert blocks within the footer region to Bootstrap panels.
+ *
+ * @param array $build
+ *   The block view render array to alter.
+ *
+ * @see dr821m_block_view_alter()
+ */
+function _dr821_block_view_alter(array &$build) {
+  /** @var \Drupal\block\Entity\Block $blockEntity */
+  $blockEntity = $build['#block'];
+  $region = $blockEntity->getRegion();
+  if ($region !== 'footer') {
+    return;
+  }
+  // Request wrapping the block title and content in appropriate classes.
+  $build['#pre_render'][] = '_dr821_prerender_block';
+
+  // Wrap the overall block in panel classes.
+  if (!isset($build['#attributes']['class'])) {
+    $build['#attributes']['class'] = [];
+  }
+  $build['#dr821_panelize_title_va'] = TRUE;
+  $build['#attributes']['class'] += ['panel', 'panel-default', 'col-xs-6'];
+}
+
+/**
+ * Pre-render function to request wrapping of block parts.
+ *
+ * @param array $block
+ *
+ * @return mixed
+ */
+function _dr821_prerender_block($block) {
+  // Wrap the block body in a panel-body container div.
+  if (!empty($block['content'])) {
+    $block['content']['#theme_wrappers'] = [
+      'container' => [
+        '#attributes' => [
+          'class' => ['panel-body'],
+        ],
+      ],
+    ];
+  }
+  // Tell the preprocess function to wrap the block title as a panel heading
+  $block['#dr821_panelize_title'] = TRUE;
+  return $block;
+}
+
+/**
+ * Wrap the block title as a panel heading with title.
+ *
+ * @param array $elements
+ */
+function _dr821_panelize_block_title(&$elements) {
+  // Do not just assign prefix/suffix: it would lose contextual information.
+  $elements['title_prefix']['#markup'] = '<div class="panel-heading">';
+  $elements['title_suffix']['#markup'] = '</div>';
+  $elements['title_attributes']['class'][] = 'panel-title';
+}
+
+/**
+ * Implements hook_preprocess_block().
+ *
+ * Wrap the block title as a panel heading if required.
+ */
+function dr821_preprocess_block(&$elements, $hook, $info) {
+  if ($elements['elements']['#dr821_panelize_title']) {
+    _dr821_panelize_block_title($elements);
+  }
+}

+ 16 - 0
js/panelize.js

@@ -0,0 +1,16 @@
+(function ($, _) {
+  "use strict";
+  var $bodies = $('.region-help  h2')
+    .addClass('panel-title')
+    .wrap('<div class="panel-heading"></div>')
+    .parent()
+    .parent()
+    .children(':last-child');
+
+  $bodies
+    .addClass('panel-body');
+
+  $bodies
+    .parent()
+    .addClass('panel panel-default col-sm-6');
+}(window.jQuery, window._));

+ 7 - 0
module/dr821m.info.yml

@@ -0,0 +1,7 @@
+name: DR-821
+description: 'Support module for DR-821 theme'
+core: 8.x
+type: module
+package: 'OSInet Formation'
+tags:
+  - themer

+ 21 - 0
module/dr821m.module

@@ -0,0 +1,21 @@
+<?php
+
+/**
+ * Support module for DR-821 theme.
+ *
+ * It implements hooks a theme cannot implement.
+ */
+
+use Drupal\Core\Block\BlockPluginInterface;
+
+/**
+ * Implements hook_block_view_alter().
+ *
+ * Provides this capability to the theme.
+ */
+function dr821m_block_view_alter(array &$build) {
+  // Only activate if DR821 is the active theme.
+  if (\Drupal::theme()->getActiveTheme()->getName() == 'dr821') {
+    _dr821_block_view_alter($build);
+  }
+}

+ 3 - 6
templates/layout/page.html.twig

@@ -68,7 +68,7 @@
     </div>
   </div>
 
-  <div class="row">
+  <div class="row region-help">
     <div class="col-md-12">
       {{ page.help }}
     </div>
@@ -109,12 +109,9 @@
     </div>
   {% endif %}
 
-  {% if page.footer_first or page.footer_second or page.footer_third or page.footer_fourth %}
+  {% if page.footer %}
     <footer role="contentinfo" class="row">
-      <div class="col-md-3">{{ page.footer_first }}</div>
-      <div class="col-md-3">{{ page.footer_second }}</div>
-      <div class="col-md-3">{{ page.footer_third }}</div>
-      <div class="col-md-3">{{ page.footer_fourth }}</div>
+      {{ page.footer }}
     </footer>
   {% endif %}