Jump to content

Customize the output of field group titles in listing form


Alejandro

Recommended Posts

Using a filter that intercepts the output of a controller action, it is possible to make replacements and modify that output before its shown on the page. Using this approach, you can change how the field group titles are shown on the page by replacing them with your own HTML.

<?php

Clickfwd\Hook\Filter::add('after_filter_output_listings_edit', 'jreviews_replace_form_group_titles');
Clickfwd\Hook\Filter::add('after_filter_output_listings__loadForm', 'jreviews_replace_form_group_titles');

function jreviews_replace_form_group_titles($output, $params) 
{
    // Listing editing returns HTML, while listing submit returns JSON
    $isHtmlOutput = $output[0] !== '{';
    
    if ($isHtmlOutput) {
        $tmp = $output;
    } else {
        $output = json_decode($output, true);
        $tmp = $output['html'];
    }

    // Replace the "Hotel Info" field group legend tag with an HTML header
    $hotelHeader = <<<HTML
<div class="fwd-bg-teal-600 fwd-rounded-t-lg fwd-text-white fwd-p-4">
    <h3 class="fwd-font-bold fwd-text-2xl">Some Header</h3>
    <p class="fwd-text-base">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sed ipsum a ipsum tincidunt cursus. Vivamus urna tortor, dictum vitae felis ac, luctus elementum ligula. Vivamus ultrices ac sapien in scelerisque.<p>
</div>
HTML;

    $tmp = str_replace('<legend>Hotel Info</legend>', $hotelHeader, $tmp);
    
    if ($isHtmlOutput) {
        return $tmp;
    }

    $output['html'] = $tmp;

    return json_encode($output);
}

Here's the gist  https://gist.github.com/jreviews/cdf5cb44467007a766cfeae48471176d

image.png

Link to comment
×
×
  • Create New...