Add Footer Block options to make_block

This commit is contained in:
Tom 2023-08-30 13:59:00 +02:00
parent 19d77064b0
commit efb2a51216
9 changed files with 185 additions and 12 deletions

View file

@ -71,6 +71,8 @@ func (i info) Run(context wisski_distillery.Context) (err error) {
context.Printf("Last Update: %v\n", info.LastUpdate.String())
context.Printf("Last Cron: %v\n", info.LastCron.String())
context.Printf("Theme: %v\n", info.Theme)
context.Printf("Bundles: (count %d)\n", info.Statistics.Bundles.TotalBundles)
for _, bundle := range info.Statistics.Bundles.Bundles {
if bundle.Count == 0 {

View file

@ -9,6 +9,7 @@ import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php/extras"
"github.com/rs/zerolog"
"github.com/tkw1536/goprogram/exit"
)
@ -18,12 +19,25 @@ var MakeBlock wisski_distillery.Command = makeBlock{}
type makeBlock struct {
Title string `short:"t" long:"title" description:"title of block to create"`
Region string `short:"r" long:"region" description:"optional region to assign block to"`
Footer bool `short:"f" long:"footer" description:"create block in the footer region"`
Positionals struct {
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to create legal block for"`
} `positional-args:"true"`
}
var errFooterAndRegion = exit.Error{
Message: "`--footer` and `--region` provided",
ExitCode: exit.ExitCommandArguments,
}
func (mb makeBlock) AfterParse() error {
if mb.Region != "" && mb.Footer {
return errFooterAndRegion
}
return nil
}
func (makeBlock) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: cli.Requirements{
@ -39,6 +53,16 @@ var errBlocksGeneric = exit.Error{
ExitCode: exit.ExitGeneric,
}
var errBlocksFooterFailed = exit.Error{
Message: "unable to determine footer block",
ExitCode: exit.ExitGeneric,
}
var errBlocksNoFooter = exit.Error{
Message: "no footer known for region",
ExitCode: exit.ExitGeneric,
}
var errBlocksNoContent = exit.Error{
Message: "unable to read content from standard input",
ExitCode: exit.ExitCommandArguments,
@ -52,10 +76,16 @@ func (mb makeBlock) Run(context wisski_distillery.Context) error {
return errPathbuilderWissKI.Wrap(err)
}
// read the content
content, err := io.ReadAll(context.Stdin)
if err != nil {
return errBlocksNoContent.Wrap(err)
// get the footer (if any)
if mb.Footer {
zerolog.Ctx(context.Context).Info().Msg("checking for footer")
region, err := instance.Blocks().GetFooterRegion(context.Context, nil)
if err != nil {
return errBlocksFooterFailed.Wrap(err)
}
if region == "" {
return errBlocksNoFooter
}
}
id := ""
@ -63,6 +93,12 @@ func (mb makeBlock) Run(context wisski_distillery.Context) error {
id = fmt.Sprintf("block-auto-%d", time.Now().Unix())
}
// read the content
content, err := io.ReadAll(context.Stdin)
if err != nil {
return errBlocksNoContent.Wrap(err)
}
{
err := instance.Blocks().Create(context.Context, nil, extras.Block{
Info: mb.Title,

View file

@ -46,14 +46,6 @@
<a href="{{ .Info.URL }}" target="_blank" rel="noopener noreferrer">{{ .Info.URL }}</a>
</td>
</tr>
<tr>
<td>
Docker Base Image
</td>
<td>
<code>{{ .Instance.GetDockerBaseImage }}</code>
</td>
</tr>
<tr>
<td>
Running
@ -137,6 +129,56 @@
</div>
</div>
<div class="pure-u-1 pure-u-xl-2-5">
<div class="padding">
<div class="overflow">
<table class="pure-table pure-table-bordered">
<thead>
<tr>
<th colspan="2">
Drupal Info
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Theme
</td>
<td>
<code>{{ .Info.Theme }}</code>
</td>
</tr>
<tr>
<td>
Docker Base Image
</td>
<td>
<code>{{ .Instance.System.GetDockerBaseImage }}</code>
</td>
</tr>
<tr>
<td>
OPCache Development Config
</td>
<td>
<code>{{ .Instance.System.OpCacheDevelopment }}</code>
</td>
</tr>
<tr>
<td>
Content Security Policy
</td>
<td>
<code>{{ .Instance.System.ContentSecurityPolicy }}</code>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="pure-u-1 pure-u-xl-2-5">
<div class="padding">
<div class="overflow">

View file

@ -29,6 +29,9 @@ type WissKI struct {
LastUpdate time.Time
LastCron time.Time
// current theme
Theme string
// Statistics of the WissKI
Statistics Statistics

View file

@ -34,3 +34,8 @@ func (blocks *Blocks) Create(ctx context.Context, server *phpx.Server, block Blo
err = blocks.Dependencies.PHP.ExecScript(ctx, server, nil, blocksPHP, "create_basic_block", block.Info, block.Content, block.Region, block.BlockID)
return err
}
func (blocks *Blocks) GetFooterRegion(ctx context.Context, server *phpx.Server) (region string, err error) {
err = blocks.Dependencies.PHP.ExecScript(ctx, server, &region, blocksPHP, "get_footer_region")
return
}

View file

@ -33,4 +33,33 @@ function create_basic_block(string $info, string $html, string $region, string $
'weight' => 0,
]);
$block->save();
}
/** get_footer_region returns the region that implements the footer */
function get_footer_region(): string {
$footer_block_map = [
"teriyaki" => "footer_bottom",
"olivero" => "footer_bottom",
"bartik" => "footer_fifth",
"ffbartik" => "footer_fifth",
"dxpr_theme" => "footer",
"bootstrap" => "footer",
"bootstrap4" => "footer",
"bootstrap5" => "footer",
"bootstrap_for_drupal" => "footer_sub_center",
"bootstrap_for_drupal_subtheme" => "footer_sub_center",
"roma_theme" => "footer_fifth",
"gnm2018" => "footer",
"oin_graphik" => "footer",
"oin_paleo" => "footer",
"oin_projekt" => "footer",
];
$theme = \Drupal::service('theme.manager')->getActiveTheme();
if (!$theme) {
return "";
}
return $footer_block_map[$theme->getName()] ?? ""; // return the theme
}

View file

@ -0,0 +1,41 @@
package extras
import (
"context"
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
"github.com/FAU-CDI/wisski-distillery/internal/status"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
_ "embed"
)
// Prefixes implements reading and writing prefix
type Theme struct {
ingredient.Base
Dependencies struct {
PHP *php.PHP
}
}
//go:embed theme.php
var themePHP string
// Get returns the currently active theme
func (t *Theme) Get(ctx context.Context, server *phpx.Server) (theme string, err error) {
err = t.Dependencies.PHP.ExecScript(
ctx, server, &theme, themePHP,
"get_active_theme",
)
return
}
func (t *Theme) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
if flags.Quick {
return
}
info.Theme, _ = t.Get(flags.Context, flags.Server)
return
}

View file

@ -0,0 +1,14 @@
<?php
/**
* Gets the actve theme of this WissKI
*
* @return string
*/
function get_active_theme(): string {
$theme = \Drupal::service('theme.manager')->getActiveTheme();
if (!$theme) {
return "";
}
return $theme->getName();
}

View file

@ -122,6 +122,7 @@ func (wisski *WissKI) allIngredients() []initFunc {
auto[*extras.Blocks],
auto[*extras.Requirements],
auto[*extras.Adapters],
auto[*extras.Theme],
auto[*users.Users],
auto[*users.UserPolicy],