getkirby / editor

A new type of WYSIWYG editor for Kirby
https://getkirby.com
205 stars 28 forks source link

Question: extending editor block class in plugin question #97

Open bnomei opened 5 years ago

bnomei commented 5 years ago

in my plugin i have a class extending the editor. https://github.com/bnomei/kirby3-srcset/blob/2ed1d7e38c131c6545f793d74b236ae2844ef489/classes/Kirby/Editor/SrcsetBlock.php#L9

but the complete plugin consists of more then the editor block. will it break if the editor is not installed? my guess is not since the class will never be called?

i am loading the class with composer https://github.com/bnomei/kirby3-srcset/issues/12

but that should not matter either until my class is called? which it will not when the editor is not installed/used?

bnomei commented 5 years ago

NOPE. i am getting an error on composer install

Fatal error: Class 'Kirby\Editor\Block' not found in /%%USER%%/kirby3-srcset/classes/Kirby/Editor/SrcsetBlock.php on line 9 PHP Fatal error: Class 'Kirby\Editor\Block' not found in /%%USER%%/kirby3-srcset/classes/Kirby/Editor/SrcsetBlock.php on line 9 Script composer install handling the kirby event returned with error code 255

i added the %%USER%%part. :)

bnomei commented 5 years ago

solved that in adding a faux class. composer runs now.

<?php
namespace Kirby\Editor;

use Throwable;

if (!class_exists('Kirby\Editor\Block')) {
    class Block { }
}

final class SrcsetBlock extends Block
{
bnomei commented 5 years ago

this made me pass unittests

<?php

namespace Kirby\Editor;

use Throwable;
if (!class_exists('Kirby\Editor\Block')) {
    load([
        'kirby\editor\block' => __DIR__ . '/../../../tests/site/plugins/editor/lib/Block.php',
        'kirby\editor\blocks' => __DIR__ . '/../../../tests/site/plugins/editor/lib/Blocks.php',
    ]);
}
final class SrcsetBlock extends Block
{
//...
bnomei commented 4 years ago

@bastianallgeier my fix broke recently. it seems that since my srcsetblock depends inherits from you block class loading order is important but not guaranteed in composer setups (for reasons unclear to me). https://github.com/bnomei/kirby3-srcset/issues/15

i solved this by duplicating your block and blocks classes to my project but i think its a horrible idea. https://github.com/bnomei/kirby3-srcset/blob/aeafd2a71ac39dd9f4c472205d8c151bda612391/classes/Kirby/Editor/SrcsetBlock.php#L20

maybe we could solve this inheritance problem better?