Load the textarea field into another field in the panel

I was trying to load the textarea field into another field, similar to how datetime loads the date and time fields.

<?php
use Kirby\Panel\Form;

class SplitfieldField extends BaseField {
	public function content() {
		$textarea = form::field('textarea');
		echo $textarea;
	}
}

I get this error:

Fatal error: Call to a member function url() on a non-object in C:\wamp\www\splitfield\panel\app\fields\textarea\buttons.php on line 32

  1. Is it a bug?
  2. Can I get around it without copy the whole field code?

I register the field from a plugin file like this:

Might be good to know if it can be related to a bug. I also use Kirby 2.3 beta.

$kirby->set('field', 'splitfield',  __DIR__ . DS . 'field');

Update

I could do this:

$textarea = form::field('textarea', array('buttons' => false));
echo $textarea;

But then I will not get the buttons. Even if the textarea now work, the assets are not loaded.

Maybe it’s simply not a good way to do this? I just feel like duplicating the whole textarea field (which is quite large) is not the best way, but maybe it is.

could you extend the textarea field instead of the basefield?

Yes, that worked! Really simple. Here is the final code.

<?php
class SplitfieldField extends TextareaField {
  public function input() {
    $input = parent::input();
    $input->tag('textarea');
    $input->removeAttr('type');
    $input->removeAttr('value');
    $input->html($this->value() ? htmlentities($this->value(), ENT_NOQUOTES, 'UTF-8') : false);
    $input->data('field', 'editor');
    return $input;
  }
}

It also works with arguments from the blueprint. Great! Thanks!

1 Like

You’re welcome! looking forward to the next plugin :wink:

1 Like