I am doing a custom plugin area for displaying some data in a views footer (Drupal 8).

I do something about just like this : Create a custom area plugin

The only point is, instead of #markup in the return array of render() method, I would like to return some more complex stuff. If I try to return a textfield if works:

return  [
  '#type' => 'textfield',

If I try another form API element (defined via a @FormElement): it does not render.

return  [
  '#type' => 'datetime',

Two questions:

  • Should it render ?

  • If not, I can render a block there using this (ViewsBlockArea) how to do the equivalent but with a FormElement instead ? (actually rendering a form API render array.)

EDIT: Here a the finality of what I want to render:

$element['form'] = [
  '#type' => 'commerce_coupon_redemption_form',
  '#order_id' => $order->id(),
  '#cardinality' => 1,
  '#element_ajax' => [
    [get_class($this), 'ajaxRefreshSummary'],

But you may see that more trivial render array like the datetime one given above does not work either.

Also notice that any element defined by a @FormElement annotation from within the namespace Drupal\Core\Render\Element is okay. But @FormElement "from elsewhere" like datetime does not render.

  • Can you post your entire code. The commerce_coupon_redemption_form requires the order_id to be set. Do you provide that? – Neograph734 Jun 28 '17 at 17:36
  • I just edited the question to clarify with your request. – Dom. Jun 28 '17 at 18:00
  • Ah, I see you edited the question just as I was writing my comment. It is often better to provide full code than some stripped pseudo code as important things tend to be left out, hence my question. It is much better like this :) – Neograph734 Jun 28 '17 at 18:03
  • 5
    If you want to render it as a form, don't you want to wrap it into a call to \Drupal::formBuilder() instead? – Daniel Wehner Jun 30 '17 at 13:02

You can create block Form first. And from View UI, add a view object to your header or footer. And from View object configuration choose the form block you created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.