sylvainjule / kirby-color-palette

A color palette to pick colors from in the panel. Kirby 3 only.
57 stars 9 forks source link

The default option doesn't work #14

Open herrajon opened 4 years ago

herrajon commented 4 years ago

Kirby 3.4.3

The plugin seemst to ignore default value which brakes the page with:

Whoops \ Exception \ ErrorException (E_NOTICE)
Undefined index: background

from:

<?php
// Colour Palette
$palette    = $part->palette()->yaml();

$background = $palette['background'];
$border = $palette['border'];
$text = $palette['text'];
?>

based on blueprint:

columns:
  colours:
    width: 1/4
    fields:
      palette:
        default: whitex
        label: Litaver
        type: color-palette
        options:
          whitex:
            background: white
            text: black
            border: '#CCCCCC'
          blackx:
            background: black
            text: white
            border: '#CCCCCC'

The user must select colour to not break the page when saved.

This though works with the simple version of the blueprint options but breaks with the more detailed version above:

#simple colors
palette:
  type: color-palette
  default: '#135fdc'
  options:
    - '#135fdc'
    - '#f6917e'

To add it ignores required.

Tried various setups. Without success.

Thx

P.s. Great plugin and thank you

sylvainjule commented 3 years ago

Both default and required work fine for me with Kirby 3.5. It seems that default value are handled differently when added to already existing pages, maybe that's what was at fault.

I'm closing this, please don't hesitate to reopen if it still happens.

herrajon commented 3 years ago

Howdy Sylvain

Revisited this simple but useful plugin again. Really like the simplicity of it.

After few rounds of T&E I got the default option to work and not display an error page (error if the user selects no colour option):

In section 3.5 on the README.md for the plugin it states:

# structured colours
palette:
  type: color-palette
  default: blue
  options:
    blue:
      background: '#135fdc'
      border: '#0438c7'
    orange:
      background: '#f6917e'
      border: '#ef6a57'

This displays an Error page for me in various Kirby versions. Currently running 3.5.7.1.

But the following combination does work:

# structured colors
palette:
  type: color-palette
  default: 
    background: '#135fdc'
    border: '#0438c7'
    key: blue
  options:
    blue:
      background: '#135fdc'
      border: '#0438c7'
    orange:
      background: '#f6917e'
      border: '#ef6a57'

So in my case at least the background and border (and others if in question) attributes need to be defined with the Default along with a key value of the configured color optionn (key: blue in this case) and with one indent.

Hope this is useful.

Best, Jón