Skip to content

Commit

Permalink
Merge pull request #67 from ubc-web-services/develop
Browse files Browse the repository at this point in the history
Starterkit replace config and other areas that get missed by core
  • Loading branch information
occupant authored Dec 11, 2023
2 parents 6c49a37 + 48d7094 commit 03d8163
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 21 deletions.
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
UBC CLF 7.0.4 DRUPAL THEME (aka Galactus)
=======================================

A responsive UBC CLF (Common Look and Feel) theme for Drupal 8. Created by the
A responsive UBC CLF (Common Look and Feel) theme for Drupal 8+. Created by the
UBC IT Web Services Department.

Galactus is a *base theme* for Drupal 8, providing UBC-branded units with the
basic structure of the UBC CLF ([Common Look and Feel](http://clf.ubc.ca)). If
you need to modify the theme to suit your needs, we recommend using the
[Drupal 8 CLF theme](https://github.com/ubc-web-services/clf) as a child theme
to extend this one instead.
Galactus is a *theme* for Drupal 8+, providing UBC-branded units with the
basic structure of the UBC CLF ([Common Look and Feel](http://clf.ubc.ca)).

# Composer Builds
If you need to modify the theme to suit your needs, we recommend forking it as a [Starterkit](https://www.drupal.org/docs/core-modules-and-themes/core-themes/starterkit-theme) extend this one instead.


# Composer Install
If you're using composer, add the project with:
```
```bash
composer require ubc-web-services/galactus
```

# IE8 Support
Drupal 8 does not support Internet Explorer versions earlier than version 9 due
to jQuery version incompatibilities. If IE8 support is required, Drupal 7 should
be used instead, along with the CLF base theme
([Megatron](https://github.com/ubc-web-services/megatron)).
# Starterkit Fork
A starterkit fork will duplicate all the files from Galactus to your new theme to modify to your needs.
See the [Starterkit Documentation](https://www.drupal.org/docs/develop/theming-drupal/defining-a-theme-with-an-infoyml-file) for more details.

Considering it's a galactus fork we recommend prefixing the fork with `galactus_` although you can name it any name that doesn't conflict with another project installed on your Drupal site.
```bash
mkdir -p themes/custom
php core/scripts/drupal generate-theme --starterkit galactus --path themes/custom galactus_PROJECT
```

# Internet Explorer Support
Drupal 8+ does not support Internet Explorer versions earlier than version 9 due
to jQuery version incompatibilities.
See this [Change Record](https://www.drupal.org/node/1569578) for more details.

Drupal 10+ has removed Internet Explorer support all together. See this [Change Record](https://www.drupal.org/node/3199540) for more details.

# Contribution

CSS changes need to be made with SASS through node-sass.
CSS changes need to be made with SASS through `sass` node package.

Ensure that you have `yarn` installed.
Ensure that you have `npm` installed.
```
https://yarnpkg.com/lang/en/docs/install/
https://nodejs.org/en/download
```

Install the node packages with this command:
```
yarn install
npm install
```

You can build your CSS changes with this command:
```
yarn run build-css
npm run build:css
```

OR

You can watch changes to your SASS files with this command:
```
yarn run watch-css
npm run watch:css
```
69 changes: 68 additions & 1 deletion src/StarterKit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Drupal\starterkit_theme;
namespace Drupal\galactus;

use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Theme\StarterKitInterface;
Expand All @@ -15,6 +15,73 @@ public static function postProcess(string $working_dir, string $machine_name, st
$info = Yaml::decode(file_get_contents($info_file));
unset($info['hidden']);
file_put_contents($info_file, Yaml::encode($info));

$source_theme_name = 'galactus';

// Rename hooks in theme-settings.php.
$theme_settings_file = "$working_dir/theme-settings.php";
if (file_exists($theme_settings_file)) {
if (!file_put_contents($theme_settings_file, preg_replace("/(function )($source_theme_name)(_.*)/", "$1$machine_name$3", file_get_contents($theme_settings_file)))) {
throw new \RuntimeException("The theme-settings.php file $theme_settings_file could not be written.");
}
}

// Rename libraries in theme file.
$theme_file = "$working_dir/$machine_name.theme";
if (file_exists($theme_file)) {
if (!file_put_contents($theme_file, preg_replace("/($source_theme_name)\//", "$machine_name/", file_get_contents($theme_file)))) {
throw new \RuntimeException("The theme file $theme_file could not be written.");
}
}

// Rename install settings.
$config_dir = $working_dir . '/config/install';
$config_file = "$config_dir/$source_theme_name.settings.yml";
if (file_exists($config_file)) {
if (!file_put_contents($config_file, preg_replace("/(.*)($source_theme_name)(.*)/", "$1$machine_name$3", file_get_contents($config_file)))) {
throw new \RuntimeException("The config settings file $config_file could not be written.");
}
if (!rename($config_file, $config_dir . '/' . $machine_name . '.settings.yml')) {
throw new \RuntimeException("The file $config_file could not be moved.");
}
}

// Rename config schema.
$config_dir = $working_dir . '/config/schema';
$config_file = "$config_dir/$source_theme_name.schema.yml";
if (file_exists($config_file)) {
if (!file_put_contents($config_file, preg_replace("/(.*)($source_theme_name)(.*)/", "$1$machine_name$3", file_get_contents($config_file)))) {
throw new \RuntimeException("The config schema file $config_file could not be written.");
}

if (!rename($config_file, $config_dir . '/' . $machine_name . '.schema.yml')) {
throw new \RuntimeException("The file $config_file could not be moved.");
}
}

// Rename config files based on the theme machine name.
$file_pattern = "/block\.block\.{$source_theme_name}_([^.]+\.yml)/";
$config_install_dir = $working_dir . '/config/optional';
if ($files = @scandir($config_install_dir)) {
foreach ($files as $file) {
$location = $config_install_dir . '/' . $file;
if (is_dir($location)) {
continue;
}

if (preg_match($file_pattern, $file, $matches)) {
if (!file_put_contents($location, preg_replace("/(.*)($source_theme_name)(.*)/", "$1$machine_name$3", file_get_contents($location)))) {
throw new \RuntimeException("The config file $location could not be written.");
}
if (!rename($location, $config_install_dir . '/block.block.' . $machine_name . '_' . $matches[1])) {
throw new \RuntimeException("The file $location could not be moved.");
}
}
}
}
else {
throw new \RuntimeException("Temporary directory $working_dir cannot be opened.");
}
}

}
4 changes: 3 additions & 1 deletion templates/navigation/menu--main.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
<li{{ item.attributes.addClass(classes, 'expanded', 'dropdown').removeClass('menu-item') }}>
<div class="btn-group">
{{ link(item.title, item.url, item.attributes.addClass('btn')) }}
<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="ubc7-arrow blue down-arrow"></span></button>
{% if item.below %}
<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="ubc7-arrow blue down-arrow"></span></button>
{% endif %}
{% else %}
<li{{ item.attributes.addClass(classes, 'item').removeClass('menu-item') }}>
{{ link(item.title, item.url, {'class': ['navbar-link']}) }}
Expand Down

0 comments on commit 03d8163

Please sign in to comment.