Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
eki89 committed Feb 14, 2019
1 parent c37c16c commit 7b864a2
Show file tree
Hide file tree
Showing 42 changed files with 5,873 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# contao-advanced-form-bundle
Extended form generator for Contao 4 Open Source CMS
44 changes: 44 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name":"oveleon/contao-advanced-form-bundle",
"type":"contao-bundle",
"description":"Extended form generator for Contao 4 Open Source CMS",
"keywords":["contao","advanced-form-bundle"],
"homepage":"https://oveleon.de/",
"license":"MIT",
"authors":[
{
"name":"Oveleon",
"homepage":"https://oveleon.de/",
"role":"Developer"
}
],
"require":{
"php":"^5.6 || ^7.0",
"contao/core-bundle":"^4.4"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
},
"conflict": {
"contao/core": "*",
"contao/core-bundle": "4.4.1",
"contao/manager-plugin": "<2.0 || >=3.0"
},
"autoload":{
"psr-4": {
"Oveleon\\ContaoAdvancedFormBundle\\": "src/"
},
"classmap": [
"src/Resources/contao/"
],
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
]
},
"extra":{
"contao-manager-plugin": "Oveleon\\ContaoAdvancedFormBundle\\ContaoManager\\Plugin"
}
}
17 changes: 17 additions & 0 deletions src/ContaoAdvancedFormBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/*
* This file is part of Oveleon AdvancedFormBundle.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoAdvancedFormBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ContaoAdvancedFormBundle extends Bundle
{
}
46 changes: 46 additions & 0 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* This file is part of Oveleon DeveloperBundle.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoAdvancedFormBundle\ContaoManager;

use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Oveleon\ContaoAdvancedFormBundle\ContaoAdvancedFormBundle;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class Plugin implements BundlePluginInterface, RoutingPluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser): array
{
return [
BundleConfig::create(ContaoAdvancedFormBundle::class)
->setLoadAfter([ContaoCoreBundle::class])
->setReplace(['advanced-form']),
];
}

/**
* {@inheritdoc}
*/
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel)
{
return $resolver
->resolve(__DIR__.'/../Resources/config/routing.yml')
->load(__DIR__.'/../Resources/config/routing.yml')
;
}
}
118 changes: 118 additions & 0 deletions src/Controller/AjaxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace Oveleon\ContaoAdvancedFormBundle\Controller;

use Oveleon\ContaoAdvancedFormBundle\AdvancedForm;
use Oveleon\ContaoAdvancedFormBundle\AdvancedFormDataModel;
use Oveleon\ContaoAdvancedFormBundle\AdvancedFormModel;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Validation\Article;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* Handles the advanced form frontend routes.
*
* @Route(defaults={"_scope" = "frontend", "_token_check" = true})
*/
class AjaxController extends Controller
{
/**
* Runs the command scheduler.
*
* @return Response
*
* @Route("/contaoadvancedform", name="advanced_form")
*/
public function indexAction()
{
$this->container->get('contao.framework')->initialize();

return new Response('<html><body>not used</body></html>');
}

/**
* Runs the command scheduler.
*
* @return Response
*
* @Route("/contaoadvancedform/{id}", name="advanced_form_action", requirements={"id"="\d+"})
*/
public function formAction($id)
{
$this->container->get('contao.framework')->initialize();

$controller = new \FrontendIndex();

$objContent = \ContentModel::findByPk($id);

if ($objContent === null)
{
return new Response('');
}

\Environment::set('hideScript', true);

return new Response($controller->replaceInsertTags($controller->getContentElement($objContent)));
}

/**
* Runs the command scheduler.
*
* @return Response
*
* @Route("/contaoadvancedform/{ceId}/edit/{moduleId}/{column}/{dataId}/start", name="advanced_form_start_edit_action", requirements={"ceId"="\d+"})
*/
public function startEditAction($ceId, $moduleId, $column, $dataId)
{
$this->container->get('contao.framework')->initialize();

$controller = new \FrontendIndex();

$objData = AdvancedFormDataModel::findByPk($dataId);
$rawData = \StringUtil::deserialize($objData->rawData);

\Environment::set('hideScript', true);
\Environment::set('AdvancedForm', $ceId);
\Environment::set('AdvancedFormModule', $moduleId);
\Environment::set('AdvancedFormColumn', $column);
\Environment::set('AdvancedFormData', $rawData);
$_SESSION['AdvancedFormDataID'] = $dataId;
\Environment::set('AdvancedFormMode', 'update');
\Environment::set('AdvancedFormUpdate', 'start');

$objContentElement = \ContentModel::findByPk($ceId);
$objArticle = \ArticleModel::findByPk($objContentElement->pid);
$objPage = $objArticle->getRelated('pid');

return $controller->renderPage($objPage);
}

/**
* Runs the command scheduler.
*
* @return Response
*
* @Route("/contaoadvancedform/{ceId}/edit/{moduleId}/{column}/{dataId}", name="advanced_form_edit_action", requirements={"ceId"="\d+"})
*/
public function editAction($ceId, $moduleId, $column, $dataId)
{
$this->container->get('contao.framework')->initialize();

$controller = new \FrontendIndex();

$objModule = \ModuleModel::findByPk($moduleId);

\Environment::set('hideScript', true);
\Environment::set('AdvancedForm', $ceId);
\Environment::set('AdvancedFormModule', $moduleId);
\Environment::set('AdvancedFormColumn', $column);
\Environment::set('AdvancedFormMode', 'update');

$objContentElement = \ContentModel::findByPk($ceId);
$objArticle = \ArticleModel::findByPk($objContentElement->pid);
$objPage = \PageModel::findByPk($objArticle->pid);

return $controller->renderPage($objPage);
}
}
10 changes: 10 additions & 0 deletions src/Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
oveleon:
resource: "@ContaoAdvancedFormBundle/Controller"
type: annotation

oveleon_advancedform:
path: /contaoadvancedform/
defaults:
_scope: frontend
_controller: "FrameworkBundle:Redirect:redirect"
route: advanced_form
60 changes: 60 additions & 0 deletions src/Resources/contao/classes/AdvancedFormField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
* This file is part of Oveleon AdvancedForm.
*
* (c) https://www.oveleon.de/
*/

namespace Oveleon\ContaoAdvancedFormBundle;


class AdvancedFormField
{
/**
* @param $arrFields
* @param $formId
* @param $form
*
* @return array
*/
public function unsetAdvancedFormFields($arrFields, $formId, $form)
{
if (get_class($form) !== 'Oveleon\ContaoAdvancedFormBundle\AdvancedForm')
{
foreach ($arrFields as $key => $field)
{
if ($field->ptable !== 'tl_form')
{
unset($arrFields[$key]);
}
}
}

return $arrFields;
}

/**
* @param \PageModel $objPage
* @param \LayoutModel $objLayout
* @param \PageRegular $pageRegular
*/
public function removeModulesFromLayout(&$objPage, &$objLayout, $pageRegular)
{
if (\Environment::get('AdvancedForm'))
{
$modules = array
(
array
(
'mod' => \Environment::get('AdvancedFormModule'),
'col' => \Environment::get('AdvancedFormColumn'),
'enable' => 1
)
);

$objLayout->modules = serialize($modules);
$objPage->cssClass .= ' modal';
}
}
}
49 changes: 49 additions & 0 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of Oveleon AdvancedForm.
*
* (c) https://www.oveleon.de/
*/

// Back end modules
array_insert($GLOBALS['BE_MOD']['content'], 4, array
(
'advanced_form' => array
(
'tables' => array('tl_advanced_form', 'tl_advanced_form_page', 'tl_form_field', 'tl_advanced_form_data')
)
));

// Front end modules
array_insert($GLOBALS['FE_MOD']['application'], 1, array
(
'advancedForm' => '\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedForm',
'advancedFormData' => '\\Oveleon\\ContaoAdvancedFormBundle\\ModuleAdvancedFormData',
));

// Content elements
array_insert($GLOBALS['TL_CTE']['includes'], 3, array
(
'advancedForm' => '\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedForm',
));

// Frontend form fields
array_insert($GLOBALS['TL_FFL'], -1, array
(
'login' => '\\Oveleon\\ContaoAdvancedFormBundle\\FormLogin',
'map' => '\\Oveleon\\ContaoAdvancedFormBundle\\FormMapField',
'range' => '\\Oveleon\\ContaoAdvancedFormBundle\\FormRangeField',
'usermail' => '\\Oveleon\\ContaoAdvancedFormBundle\\FormUserMail',
'username' => '\\Oveleon\\ContaoAdvancedFormBundle\\FormUserName',
));

// Models
$GLOBALS['TL_MODELS']['tl_advanced_form'] = '\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedFormModel';
$GLOBALS['TL_MODELS']['tl_advanced_form_page'] = '\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedFormPageModel';
$GLOBALS['TL_MODELS']['tl_advanced_form_data'] = '\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedFormDataModel';
$GLOBALS['TL_MODELS']['tl_form_field'] = '\\Oveleon\\ContaoAdvancedFormBundle\\FormFieldModel';

// Hooks
$GLOBALS['TL_HOOKS']['compileFormFields'][] = array('\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedFormField', 'unsetAdvancedFormFields');
$GLOBALS['TL_HOOKS']['getPageLayout'][] = array('\\Oveleon\\ContaoAdvancedFormBundle\\AdvancedFormField', 'removeModulesFromLayout');
Loading

0 comments on commit 7b864a2

Please sign in to comment.