FEATURE #1370: add form for creating new static page
This commit is contained in:
@@ -1,10 +1,46 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Modules\StaticPages\Http\Controllers\Admin;
|
namespace Modules\StaticPages\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\Content;
|
||||||
|
use Modules\StaticPages\Http\Requests\CreateNewStaticPageRequest;
|
||||||
|
|
||||||
class CreateNewStaticPage extends Controller
|
class CreateNewStaticPage extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Display form for new static page
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
public function getNew()
|
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',
|
'prefix' => 'admin/pages',
|
||||||
'namespace' => 'Modules\StaticPages\Http\Controllers\Admin'
|
'namespace' => 'Modules\StaticPages\Http\Controllers\Admin'
|
||||||
], function () {
|
], function () {
|
||||||
|
|
||||||
|
// list of all static pages
|
||||||
Route::get('overview', 'StaticPageOverview@getOverview')
|
Route::get('overview', 'StaticPageOverview@getOverview')
|
||||||
->name('staticpage.overview');
|
->name('staticpage.overview');
|
||||||
|
|
||||||
|
// form for creating new static page
|
||||||
Route::get('new', 'CreateNewStaticPage@getNew')
|
Route::get('new', 'CreateNewStaticPage@getNew')
|
||||||
->name('staticpage.new');
|
->name('staticpage.new');
|
||||||
|
|
||||||
|
// form for editing existing static page
|
||||||
Route::get('edit/{id}', 'EditStaticPage@getEdit')
|
Route::get('edit/{id}', 'EditStaticPage@getEdit')
|
||||||
->name('staticpage.edit');
|
->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;
|
<?php namespace Modules\Staticpages\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Lang;
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
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.
|
* Boot the application events.
|
||||||
*
|
*
|
||||||
* @var bool
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected $defer = false;
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->registerTranslations();
|
||||||
|
$this->registerConfig();
|
||||||
|
$this->registerViews();
|
||||||
|
|
||||||
/**
|
// register links in admin menu
|
||||||
* Boot the application events.
|
$menu = \Menu::instance('mainMenu');
|
||||||
*
|
$menu->dropdown(trans('staticpages::adminMenu.staticPages'), function ($submenu) {
|
||||||
* @return void
|
$submenu->route('staticpage.new', trans('staticpages::adminMenu.new'));
|
||||||
*/
|
$submenu->route('staticpage.overview', trans('staticpages::adminMenu.overview'));
|
||||||
public function boot()
|
}, 15, ['icon' => 'fa fa-newspaper-o']);
|
||||||
{
|
}
|
||||||
$this->registerTranslations();
|
|
||||||
$this->registerConfig();
|
|
||||||
$this->registerViews();
|
|
||||||
|
|
||||||
// register links in admin menu
|
/**
|
||||||
$menu = \Menu::instance('mainMenu');
|
* Register the service provider.
|
||||||
$menu->dropdown(trans('staticpages::adminMenu.staticPages'), function($submenu) {
|
*
|
||||||
$submenu->route('staticpage.new', trans('staticpages::adminMenu.new'));
|
* @return void
|
||||||
$submenu->route('staticpage.overview', trans('staticpages::adminMenu.overview'));
|
*/
|
||||||
}, 15, ['icon' => 'fa fa-newspaper-o']);
|
public function register()
|
||||||
}
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the service provider.
|
* Register config.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function register()
|
protected function registerConfig()
|
||||||
{
|
{
|
||||||
//
|
$this->publishes([
|
||||||
}
|
__DIR__ . '/../Config/config.php' => config_path('staticpages.php'),
|
||||||
|
]);
|
||||||
|
$this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'staticpages');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register config.
|
* Register views.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function registerConfig()
|
public function registerViews()
|
||||||
{
|
{
|
||||||
$this->publishes([
|
$viewPath = base_path('resources/views/modules/staticpages');
|
||||||
__DIR__.'/../Config/config.php' => config_path('staticpages.php'),
|
|
||||||
]);
|
|
||||||
$this->mergeConfigFrom(
|
|
||||||
__DIR__.'/../Config/config.php', 'staticpages'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$sourcePath = __DIR__ . '/../Resources/views';
|
||||||
* Register views.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function registerViews()
|
|
||||||
{
|
|
||||||
$viewPath = base_path('resources/views/modules/staticpages');
|
|
||||||
|
|
||||||
$sourcePath = __DIR__.'/../Resources/views';
|
$this->publishes([
|
||||||
|
$sourcePath => $viewPath
|
||||||
|
]);
|
||||||
|
|
||||||
$this->publishes([
|
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||||
$sourcePath => $viewPath
|
return $path . '/modules/staticpages';
|
||||||
]);
|
}, \Config::get('view.paths')), [$sourcePath]), 'staticpages');
|
||||||
|
}
|
||||||
|
|
||||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
/**
|
||||||
return $path . '/modules/staticpages';
|
* Register translations.
|
||||||
}, \Config::get('view.paths')), [$sourcePath]), 'staticpages');
|
*
|
||||||
}
|
* @return void
|
||||||
|
*/
|
||||||
/**
|
public function registerTranslations()
|
||||||
* Register translations.
|
{
|
||||||
*
|
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'staticpages');
|
||||||
* @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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the services provided by the provider.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function provides()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
return [
|
return [
|
||||||
'overview' => 'List of all static pages',
|
'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