Skip to content

Commit

Permalink
Merge pull request #48 from helsingborg-stad/feat/acf-fronted-form
Browse files Browse the repository at this point in the history
Feat/acf fronted form
  • Loading branch information
sebastianthulin authored Mar 11, 2024
2 parents 75ea358 + 4ebdfbb commit d649f53
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/php/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace EventManager;

use EventManager\Helper\Hookable;
use EventManager\Helper\HooksRegistrar\HooksRegistrarInterface;
use EventManager\Services\WPService\WPService;
use EventManager\SetPostTermsFromContent\SetPostTermsFromContent;
Expand All @@ -29,6 +28,7 @@ public function registerHooks(HooksRegistrarInterface $hooksRegistrar)
->register(new \EventManager\ApiResponseModifiers\Event())
->register(new SetPostTermsFromContent($tagReader, $this->wpService, 'event', 'keyword'))
->register(new \EventManager\Modifiers\ModifyPostContentBeforeReadingTags($this->wpService))
->register(new \EventManager\CleanupUnusedTags\CleanupUnusedTags('keyword', $this->wpService));
->register(new \EventManager\CleanupUnusedTags\CleanupUnusedTags('keyword', $this->wpService))
->register(new \EventManager\Modules\FrontendForm\Register($this->wpService));
}
}
45 changes: 45 additions & 0 deletions source/php/Helper/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace EventManager\Helper;

use EventManager\Services\WPService\WPService;

abstract class Module implements Hookable
{
protected WPService $wp;

abstract public function getModuleName(): string;
abstract public function getModulePath(): string;

public function __construct(WPService $wpService)
{
$this->wp = $wpService;
}

public function addHooks(): void
{
$this->wp->addAction('init', [$this, 'register']);
$this->wp->addFilter('/Modularity/externalViewPath', [$this, 'addViewPath']);
}

public function addViewPath($paths): array
{
$paths['mod-event-form'] = $this->getModulePath() . '/views';
return $paths;
}

public function register(): bool
{
//Register the module
if (function_exists('modularity_register_module')) {
modularity_register_module(
$this->getModulePath(),
$this->getModuleName()
);

return true;
}

throw new \Exception('Modularity not found');
}
}
6 changes: 6 additions & 0 deletions source/php/HideUnusedAdminPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public function addHooks(): void

public function hideUnusedAdminPages()
{
//Do not hide admin pages on local environment
if(wp_get_environment_type() === 'local') {
return;
}

//Hide unused admin pages
$this->wpService->removeMenuPage('edit.php');
$this->wpService->removeMenuPage('edit.php?post_type=page');
$this->wpService->removeMenuPage('link-manager.php');
Expand Down
76 changes: 76 additions & 0 deletions source/php/Modules/FrontendForm/FrontendForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
/** @noinspection PhpFullyQualifiedNameUsageInspection */
/** @noinspection PhpUndefinedClassInspection */
/** @noinspection PhpUndefinedNamespaceInspection */

namespace EventManager\Modules\FrontendForm;

//use EventManager\Helper\CacheBust;

/**
* @property string $description
* @property string $namePlural
* @property string $nameSingular
* @property int $ID
*/
class FrontendForm extends \Modularity\Module
{
public $slug = 'event-form';
public $supports = [];

public function init(): void
{
$this->nameSingular = __('Event Form', );
$this->namePlural = __('Event Forms', 'api-event-manager');
$this->description = __('Module for creating public event form', 'api-event-manager');
//$this->cacheTtl = 60;
}

public function data(): array
{
$fields = $this->getFields();

return [
'formStart' => function() {

},
'form' => function() {
acf_form([
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => [
'post_type' => 'event',
'post_status' => 'draft'
],
'submit_value' => __('Create Event', 'api-event-manager')
]);
},
'formEnd' => function() {

},
];
}

public function template(): string
{
return 'frontend-form.blade.php';
}

public function script(): void
{
acf_form_head();
/*wp_enqueue_script(
'frontend-form',
EVENT_MANAGER_URL . '/dist/'. CacheBust::name('js/assignment-form.js')
);*/
}

public function style(): void {
/*wp_enqueue_style(
'frontend-form',
EVENT_MANAGER_URL . '/dist/'. CacheBust::name('js/assignment-form.css')
);*/
}
}
16 changes: 16 additions & 0 deletions source/php/Modules/FrontendForm/Register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace EventManager\Modules\FrontendForm;

use EventManager\Helper\Module;

class Register extends Module
{
public function getModuleName(): string {
return 'FrontendForm';
}

public function getModulePath(): string {
return EVENT_MANAGER_PATH . 'source/php/Modules/FrontendForm/';
}
}
5 changes: 5 additions & 0 deletions source/php/Modules/FrontendForm/views/frontend-form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@paper(['padding' => 4])
{!! $formStart() !!}
{!! $form() !!}
{!! $formEnd() !!}
@endpaper

0 comments on commit d649f53

Please sign in to comment.