Programmatically add a footer to a view I need add a footer to a view based on certain conditions. I followed this article and as per my understanding this should work. But this is not giving me any result.

Here is my code:


function utility_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
  $item = array(
    'id' => 'area_text_custom',
    'table' => 'views',
    'field' => 'area_text_custom',
    'relationship' => 'none',
    'group_type' => 'none',
    'admin_label' => '',
    'empty' => NULL,
    'tokenize' => NULL,
    'content' => array(
      'value' => "Footer content is great.",
      'format' => "basic_html",
    ),
    'plugin_id' => 'text',
  );
  $view->setHandler($display_id, 'footer', 'area_text_custom', $item);
}



Update: Using the above hook the footer is getting called but renders as Array
I was able to add a Views footer with some code in a custom module.

use Drupal\views\ViewExecutable;
function YOURMODULENAME_views_pre_view(ViewExecutable $view, $display_id, array &amp;$args) {
  if ($view-&gt;id() == 'view_machine_name' &amp;&amp; $display_id === 'view_display') {
    $options = array(
      'id' =&gt; 'area_text_custom',
      'table' =&gt; 'views',
      'field' =&gt; 'area_text_custom',
      'relationship' =&gt; 'none',
      'group_type' =&gt; 'none',
      'admin_label' =&gt; '',
      'empty' =&gt; TRUE,
      'tokenize' =&gt; FALSE,
      'content' =&gt; ‘Footer content is great.’,
      'plugin_id' =&gt; 'text_custom',
    );
    $view-&gt;setHandler('view_display', 'footer', 'area_text_custom', $options);
  }
}


Reference: Drupal 8: Programmatically Adding a Views Footer