Sample code for Observer used to add a column to profile on the fly

The following must be part of Magento extension and method should be registered as observer to urapidflow_profile_action event:

Observer.php
<?php
namespace \Acme\Module\Observer;
 
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
 
class RfUrlPriceObserver implements ObserverInterface
{
    /**
     * @var string
     */
    protected $columnName = 'sample_column';
 
    /**
     * @param Observer $observer
     */
    public function execute(Observer $observer )
    {
        $action  = $observer->getData( 'action' );
        $profile = $observer->getData( 'profile' );
        $proceed = $profile->getData( 'options/export/conf_child_url' );
        if ( !$proceed ) {
            return;
        }
 
        switch ( $action ) {
            case 'start':
                $columns = $profile->getColumns();
                foreach ( $columns as $col ) {
                    if ( $col[ 'field' ] == $this->columnName ) {
                        // column present, no need to do anything
                        return;
                    }
                }
 
                $columns[ ] = array(
                    'field' => $this->columnName
                );
 
                $profile->setData( 'columns', $columns );
                break;
            case 'stop': // in case we don't want to save the column, we remove it here
            case 'finish':
                $columns = $profile->getColumns();
                foreach ( $columns as $idx => $col ) {
                    if ( $col[ 'field' ] == $this->columnName ) {
                        unset( $columns[ $idx ] );
                    }
                }
 
                $profile->setData( 'columns', $columns );
                break;
            default :
                return;
                break;
        }
    }
}