PHP code example of heimrichhannot / contao-modal

1. Go to this page and download the library: Download heimrichhannot/contao-modal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heimrichhannot / contao-modal example snippets


config.php
/**
 * Modal module configuration
 */
$GLOBALS['MODAL_MODULES']['mymodule_list'] = array
(
	'invokePalette' => 'customTpl;', // The modal palette will be invoked after the field customTpl; as example
);

 public function parseArticlesHook(&$objTemplate, $arrArticle, $objModule)
 	{
 		if (!$objModule->useModal || $arrArticle['source'] != 'default') {
 			return false;
 		}
 		
 		$objJumpTo = \PageModel::findPublishedById($objTemplate->archive->jumpTo);
 		
 		if ($objJumpTo === null || !$objJumpTo->linkModal) {
 			return false;
 		}
 		
 		$objModal = ModalModel::findPublishedByIdOrAlias($objJumpTo->modal);
 		
 		if ($objModal === null) {
 			return false;
 		}
 		
 		$objJumpTo = \PageModel::findWithDetails($objJumpTo->id);
 		
 		$arrConfig = ModalController::getModalConfig($objModal->current(), $objJumpTo->layout);
 		
 		$blnAjax = true;
 		$blnRedirect = true;
 		
 		$objTemplate->link         = ModalController::generateModalUrl($arrArticle, $objTemplate->archive->jumpTo, $blnAjax, $blnRedirect);
 		$objTemplate->linkHeadline = ModalController::convertLinkToModalLink($objTemplate->linkHeadline, $objTemplate->link, $arrConfig, $blnRedirect);
 		$objTemplate->more         = ModalController::convertLinkToModalLink($objTemplate->more, $objTemplate->link, $arrConfig, $blnRedirect);
 	}

// my_module/config/config.php

/**
 * Modal types
 */
$GLOBALS['TL_MODALS']['my_custom_modal'] = array
(
	'header'   => true,
	'footer'   => true,
	'template' => 'modal_my_custom_modal',
	'link'     => array(
		'attributes' => array(
			'data-toggle' => 'modal',
		),
	),
	'js'       => array
	(
		'system/modules/my_module/assets/js/jquery.my_custom_modal.js',
	),
);