Skip to content

Commit 42c7cfe

Browse files
committed
added template for contact_form
1 parent 48d74de commit 42c7cfe

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

app/site/controllers/Admin/ContactForms.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use \App\Site\Models\Contact;
1919
use \App\Site\Models\ContactSubmission;
2020
use \App\Site\Controllers\Admin\Json\ContactCallback;
21+
use \App\App;
2122

2223
/**
2324
* "ContactForms" Admin Page
@@ -135,10 +136,11 @@ public function getFormDefinition(FAPI\Form $form, &$form_state)
135136
]
136137
);
137138

138-
$contact_title = $contact_content = $contact_submit_to = "";
139+
$contact_title = $contact_template_name = $contact_content = $contact_submit_to = "";
139140
if ($contact->isLoaded()) {
140141
$contact_title = $contact->title;
141142
$contact_content = $contact->content;
143+
$contact_template_name = $contact->template_name;
142144
$contact_submit_to = $contact->submit_to;
143145
}
144146

@@ -147,15 +149,32 @@ public function getFormDefinition(FAPI\Form $form, &$form_state)
147149
case 'new':
148150
$this->addBackButton();
149151

152+
$templates = [];
153+
$initial_dir = App::getDir(App::TEMPLATES).DS.'frontend'.DS;
154+
foreach (glob($initial_dir.'contacts'.DS.'*.php') as $template) {
155+
$key = str_replace($initial_dir, "", $template);
156+
$key = preg_replace("/\.php$/i", "", $key);
157+
$templates[$key] = basename($template);
158+
}
159+
150160
$form
151161
->addField(
152162
'title',
153163
[
154-
'type' => 'textfield',
155-
'title' => 'Title',
156-
'default_value' => $contact_title,
157-
'validate' => ['required'],
158-
]
164+
'type' => 'textfield',
165+
'title' => 'Title',
166+
'default_value' => $contact_title,
167+
'validate' => ['required'],
168+
]
169+
)
170+
->addField(
171+
'template_name',
172+
[
173+
'type' => 'select',
174+
'title' => 'Template',
175+
'default_value' => $contact_template_name,
176+
'options' => ['' => '--' ] + $templates,
177+
]
159178
)
160179
->addField(
161180
'content',
@@ -392,6 +411,7 @@ public function formSubmitted(FAPI\Form $form, &$form_state)
392411
$contact->url = $values['frontend']['url'];
393412
$contact->title = $values['title'];
394413
$contact->locale = $values['frontend']['locale'];
414+
$contact->template_name = $values['template_name'];
395415
$contact->content = $values['content'];
396416
$contact->submit_to = $values['submit_to'];
397417
$contact->website_id = $values['frontend']['website_id'];

app/site/controllers/Frontend/ContactForm.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class ContactForm extends FormPage // and and is similar to FrontendPageWithObje
4545
*/
4646
protected function getTemplateName()
4747
{
48+
if ($this->templateData['object']->getTemplateName()) {
49+
return $this->templateData['object']->getTemplateName();
50+
}
51+
4852
return 'contact_form';
4953
}
5054

@@ -78,7 +82,7 @@ public static function getRoutePath()
7882
public function process(RouteInfo $route_info = null, $route_data = [])
7983
{
8084
$this->route_info = $route_info;
81-
85+
8286
$this->templateData['object'] = $this->getContainer()->call([Contact::class, 'load'], ['id' => $route_data['id']]);
8387
if (!($this->templateData['object'] instanceof Model && $this->templateData['object']->isLoaded())) {
8488
return $this->getUtils()->errorPage(404);
@@ -178,7 +182,7 @@ public function formValidate(FAPI\Form $form, &$form_state)
178182
{
179183
return true;
180184
}
181-
185+
182186
/**
183187
* search component by name
184188
*

app/site/controllers/Frontend/Page.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ protected function getTemplateName()
4646
return 'homepage';
4747
}
4848

49+
if ($this->getObject()->getTemplateName()) {
50+
return $this->getObject()->getTemplateName();
51+
}
52+
4953
return 'page';
5054
}
5155

@@ -59,7 +63,7 @@ protected function getTemplateName()
5963
public function process(RouteInfo $route_info = null, $route_data = [])
6064
{
6165
$this->route_info = $route_info;
62-
66+
6367
if (isset($route_data['id'])) {
6468
$this->setObject($this->getContainer()->call([PageModel::class, 'load'], ['id' => $route_data['id']]));
6569
}

app/site/migrations/CreateContactTableMigration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function addDBTableDefinition(Table $table)
5353
->addColumn('meta_description', 'VARCHAR', [1024])
5454
->addColumn('html_title', 'VARCHAR', [255])
5555
->addColumn('content', 'TEXT', null)
56+
->addColumn('template_name', 'VARCHAR', [1024])
5657
->addColumn('submit_to', 'VARCHAR', [255])
5758
->addColumn('user_id', 'INT', null, ['UNSIGNED'])
5859
->addColumn('created_at', 'TIMESTAMP', null, [], false, 'CURRENT_TIMESTAMP()')

app/site/models/Contact.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @method int getWebsiteId()
2222
* @method string getTitle()
2323
* @method string getContent()
24+
* @method string getTemplateName()
2425
* @method string getMetaDescription()
2526
* @method string getMetaKeywords()
2627
* @method string getHtmlTitle()

templates/frontend/contacts/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)