FEATURE #1370: add form for creating new static page
This commit is contained in:
@@ -1,10 +1,46 @@
|
||||
<?php
|
||||
namespace Modules\StaticPages\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\Content;
|
||||
use Modules\StaticPages\Http\Requests\CreateNewStaticPageRequest;
|
||||
|
||||
class CreateNewStaticPage extends Controller
|
||||
{
|
||||
/**
|
||||
* Display form for new static page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getNew()
|
||||
{
|
||||
return view('staticpages::index');
|
||||
return view('staticpages::admin.new', ['contentStates' => []]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save new static page
|
||||
*
|
||||
* @param CreateNewStaticPageRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postNew(CreateNewStaticPageRequest $request)
|
||||
{
|
||||
$page = new Content();
|
||||
|
||||
// @todo add module_handler
|
||||
|
||||
$page->user_id = \Auth::user()->id;
|
||||
$page->title = $request->title;
|
||||
$page->published_from = $request->publishedFrom;
|
||||
$page->published_to = $request->publishedTo;
|
||||
$page->meta_keywords = $request->meta_description;
|
||||
$page->meta_description = $request->meta_description;
|
||||
$page->content = $request->pageContent;
|
||||
|
||||
$page->save();
|
||||
|
||||
return redirect()
|
||||
->route('staticpages.new')
|
||||
->with('success', trans('admin.successfullyCreated'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Modules\StaticPages\Http\Requests;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
|
||||
class CreateNewStaticPageRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'title' => 'required',
|
||||
'url' => 'required|unique:contents,url',
|
||||
'published_from' => 'date',
|
||||
'published_to' => 'date',
|
||||
'title_photo' => 'exists:files,id',
|
||||
'module_settings' => 'json',
|
||||
'status' => 'required|in:draft,protected,public'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,20 @@ Route::group([
|
||||
'prefix' => 'admin/pages',
|
||||
'namespace' => 'Modules\StaticPages\Http\Controllers\Admin'
|
||||
], function () {
|
||||
|
||||
// list of all static pages
|
||||
Route::get('overview', 'StaticPageOverview@getOverview')
|
||||
->name('staticpage.overview');
|
||||
|
||||
// form for creating new static page
|
||||
Route::get('new', 'CreateNewStaticPage@getNew')
|
||||
->name('staticpage.new');
|
||||
|
||||
// form for editing existing static page
|
||||
Route::get('edit/{id}', 'EditStaticPage@getEdit')
|
||||
->name('staticpage.edit');
|
||||
|
||||
// post method for creating new static page
|
||||
Route::post('new', 'CreateNewStaticPage@getNew')
|
||||
->name('staticpage.newPost');
|
||||
});
|
||||
@@ -1,99 +1,95 @@
|
||||
<?php namespace Modules\Staticpages\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class StaticPagesServiceProvider extends ServiceProvider {
|
||||
class StaticPagesServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
// register links in admin menu
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
$menu->dropdown(trans('staticpages::adminMenu.staticPages'), function ($submenu) {
|
||||
$submenu->route('staticpage.new', trans('staticpages::adminMenu.new'));
|
||||
$submenu->route('staticpage.overview', trans('staticpages::adminMenu.overview'));
|
||||
}, 15, ['icon' => 'fa fa-newspaper-o']);
|
||||
}
|
||||
|
||||
// register links in admin menu
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
$menu->dropdown(trans('staticpages::adminMenu.staticPages'), function($submenu) {
|
||||
$submenu->route('staticpage.new', trans('staticpages::adminMenu.new'));
|
||||
$submenu->route('staticpage.overview', trans('staticpages::adminMenu.overview'));
|
||||
}, 15, ['icon' => 'fa fa-newspaper-o']);
|
||||
}
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__ . '/../Config/config.php' => config_path('staticpages.php'),
|
||||
]);
|
||||
$this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'staticpages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerConfig()
|
||||
{
|
||||
$this->publishes([
|
||||
__DIR__.'/../Config/config.php' => config_path('staticpages.php'),
|
||||
]);
|
||||
$this->mergeConfigFrom(
|
||||
__DIR__.'/../Config/config.php', 'staticpages'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerViews()
|
||||
{
|
||||
$viewPath = base_path('resources/views/modules/staticpages');
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerViews()
|
||||
{
|
||||
$viewPath = base_path('resources/views/modules/staticpages');
|
||||
$sourcePath = __DIR__ . '/../Resources/views';
|
||||
|
||||
$sourcePath = __DIR__.'/../Resources/views';
|
||||
$this->publishes([
|
||||
$sourcePath => $viewPath
|
||||
]);
|
||||
|
||||
$this->publishes([
|
||||
$sourcePath => $viewPath
|
||||
]);
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/staticpages';
|
||||
}, \Config::get('view.paths')), [$sourcePath]), 'staticpages');
|
||||
}
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/staticpages';
|
||||
}, \Config::get('view.paths')), [$sourcePath]), 'staticpages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerTranslations()
|
||||
{
|
||||
$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'staticpages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* Register translations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerTranslations()
|
||||
{
|
||||
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'staticpages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
return [
|
||||
'overview' => 'List of all static pages',
|
||||
'new' => 'Create new static page'
|
||||
'new' => 'Create new static page',
|
||||
'content' => 'Page content',
|
||||
'save' => 'Save new page'
|
||||
];
|
||||
@@ -0,0 +1,15 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('pageName', @trans('staticpages::admin.new'))
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="row">
|
||||
<h2>@lang('staticpages::admin.new')</h2>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@include('staticpages::admin.newForm')
|
||||
</div>
|
||||
@stop
|
||||
@@ -0,0 +1,121 @@
|
||||
@if (session('success'))
|
||||
<div data-alert class="callout success">
|
||||
<strong>{{ session('success') }}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (session('error'))
|
||||
<div data-alert class="callout alert">
|
||||
<strong>{{ session('error') }}</strong>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form method="POST" action="{{route('staticpage.newPost')}}">
|
||||
{!! csrf_field() !!}
|
||||
|
||||
<ul class="tabs" data-tabs id="static-page-controls">
|
||||
<li class="tabs-title is-active">
|
||||
<a href="#basic-info" aria-selected="true">@lang('staticpages::admin.basicInfo')</a>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<a href="#meta">@lang('staticpages::admin.metaOptions')</a>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<a href="#publication">@lang('staticpages::admin.publicationOptions')</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tabs-content" data-tabs-content="static-page-controls">
|
||||
<div class="tabs-panel is-active" id="basic-info">
|
||||
<div class="row">
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
@lang('staticpages::admin.field_title')
|
||||
|
||||
<input type="text" name="title" placeholder="@lang('staticpages::admin.field_title')"
|
||||
value="{{old('title')}}" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
@lang('staticpages::admin.field_url')
|
||||
|
||||
<input type="text" name="url" placeholder="@lang('staticpages::admin.field_url')"
|
||||
value="{{old('url')}}" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="tabs-panel" id="publication">
|
||||
<div class="row">
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
@lang('staticpages::admin.field_published_from')
|
||||
|
||||
<input type="datetime" name="published_from" value="{{old('published_from')}}"
|
||||
placeholder="@lang('staticpages::admin.field_published_from')" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="columns large-6">
|
||||
<label>
|
||||
@lang('staticpages::admin.field_published_to')
|
||||
|
||||
<input type="datetime" name="published_to" value="{{old('published_to')}}"
|
||||
placeholder="@lang('staticpages::admin.field_published_to')" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="meta">
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<label>
|
||||
@lang('staticpages::admin.field_meta_keywords')
|
||||
|
||||
<input type="text" name="meta_keywords" value="{{old('meta_keywords')}}"
|
||||
placeholder="@lang('staticpages::admin.field_meta_keywords')" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<label>
|
||||
@lang('staticpages::admin.field_meta_description')
|
||||
|
||||
<textarea name="meta_description"
|
||||
placeholder="@lang('staticpages::admin.field_meta_description')" rows="5">{{old('meta_description')}}
|
||||
</textarea>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<label>
|
||||
@lang('staticpages::admin.content')
|
||||
|
||||
<textarea placeholder="@lang('staticpages::admin.content')" name="pageContent" id="pageContent"
|
||||
class="wysiwyg-editor">{{old('pageContent')}}</textarea>
|
||||
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="columns large-12">
|
||||
<button type="submit" class="button success">@lang('staticpages::admin.save')</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
@@ -1,11 +0,0 @@
|
||||
@extends('staticpages::layouts.master')
|
||||
|
||||
@section('content')
|
||||
|
||||
<h1>Hello World</h1>
|
||||
|
||||
<p>
|
||||
This view is loaded from module: {!! config('staticpages.name') !!}
|
||||
</p>
|
||||
|
||||
@stop
|
||||
Reference in New Issue
Block a user