Added new parents field with more options

This commit is contained in:
Andy Miller
2017-04-10 15:07:14 -06:00
parent 5e732e1de2
commit 7abf4b1461
9 changed files with 48 additions and 46 deletions

View File

@@ -26,11 +26,9 @@ form:
required: true
route:
type: select
label: PLUGIN_ADMIN.PAGE
type: parents
label: PLUGIN_ADMIN.PARENT
classes: fancy
data-options@: '\Grav\Common\Page\Pages::parentsRawRoutes'
data-default@: '\Grav\Plugin\Admin\Admin::rawRoute'
validate:
required: true

View File

@@ -75,13 +75,9 @@ form:
required: true
route:
type: select
type: parents
label: PLUGIN_ADMIN.PARENT
classes: fancy
data-options@: '\Grav\Common\Page\Pages::parentsRawRoutes'
data-default@: '\Grav\Plugin\Admin\Admin::rawRoute'
options:
'': PLUGIN_ADMIN.DEFAULT_OPTION_SELECT
validate:
required: true

View File

@@ -2,10 +2,6 @@ form:
validation: loose
fields:
route:
type: select
type: parents
label: PLUGIN_ADMIN.PARENT
classes: fancy
data-options@: '\Grav\Common\Page\Pages::parentsRawRoutes'
data-default@: '\Grav\Plugin\Admin\Admin::rawRoute'
options:
'/': PLUGIN_ADMIN.DEFAULT_OPTION_ROOT

View File

@@ -28,13 +28,9 @@ form:
required: true
route:
type: select
label: PLUGIN_ADMIN.PARENT_PAGE
type: parents
label: PLUGIN_ADMIN.PARENT
classes: fancy
data-options@: '\Grav\Common\Page\Pages::parentsRawRoutes'
data-default@: '\Grav\Plugin\Admin\Admin::getLastPageRoute'
options:
'/': PLUGIN_ADMIN.DEFAULT_OPTION_ROOT
validate:
required: true

View File

@@ -21,13 +21,9 @@ form:
required: true
route:
type: select
label: PLUGIN_ADMIN.PARENT_PAGE
type: parents
label: PLUGIN_ADMIN.PARENT
classes: fancy
data-options@: '\Grav\Common\Page\Pages::parentsRawRoutes'
data-default@: '\Grav\Plugin\Admin\Admin::getLastPageRoute'
options:
'/': PLUGIN_ADMIN.DEFAULT_OPTION_ROOT
validate:
required: true

View File

@@ -75,13 +75,11 @@ form:
required: true
route:
type: select
type: parents
label: PLUGIN_ADMIN.PARENT
classes: fancy
data-options@: '\Grav\Common\Page\Pages::parentsRawRoutes'
data-default@: '\Grav\Plugin\Admin\Admin::rawRoute'
options:
'/': PLUGIN_ADMIN.DEFAULT_OPTION_ROOT
validate:
required: true
name:
type: select

View File

@@ -1361,8 +1361,8 @@ class AdminController extends AdminBaseController
}
$this->admin->json_response = [
'status' => 'error',
'message' => $this->admin->translate('PLUGIN_ADMIN.NO_CHILD_TYPE')
'status' => 'success',
'child_type' => 'default'
];
return true;

View File

@@ -1,6 +1,10 @@
{% extends "forms/field.html.twig" %}
{% macro options(field, pages, value, depth) %}
{% macro options(globals, pages, depth) %}
{% set field = globals.field %}
{% set value = globals.value %}
{% set current_page = globals.admin.page %}
{% if field.options and depth == 0 %}
{% for key, value in field.options %}
@@ -13,20 +17,24 @@
{% set depth = depth +1 %}
{% endif %}
{% set indent = depth == 0 ? '' : repeat('-', depth) ~ ' ' %}
{% set indent = depth == 0 ? '' : repeat('—-', depth) ~ '▸ ' %}
{% for page in pages.children %}
{% if page.routable() or field.show_all %}
{% if not (field.show_self is same as(false) and page.rawRoute() == current_page.rawRoute()) %}
<option {% if page.route == value or (field.multiple and page.route in value) %}selected="selected"{% endif %} value="{{ page.route }}">
{% if field.show_fullpath %}
{{ page.route }}
{% else %}
{{indent}} {{ page.menu }}
{{indent|raw}} {{ page.menu }}
{% endif %}
</option>
{% endif %}
{% endif %}
{% if field.limit_levels is not defined or (depth+1 < field.limit_levels) %}
{% if page.children|length > 0 and (field.show_modular or not page.modular()) %}
{{ _self.options(field, page, value, depth + 1) }}
{{ _self.options(globals, page, depth + 1) }}
{% endif %}
{% endif %}
{% endfor %}
{% endmacro %}
@@ -39,6 +47,7 @@
{% endblock %}
{% block input %}
<div class="form-select-wrapper {{ field.size }}">
<select class="{{ field.classes }}" name="{{ (scope ~ field.name)|fieldName ~ (field.multiple ? '[]' : '') }}"
{% if field.autofocus in ['on', 'true', 1] %}autofocus="autofocus"{% endif %}
@@ -47,7 +56,12 @@
{% if field.multiple in ['on', 'true', 1] %}multiple="multiple"{% endif %}
{% if field.disabled or isDisabledToggleable %}disabled="disabled"{% endif %}
>
{{ _self.options(field,pages,value, 0) }}
{% if field.start_route %}
{% set field = field|merge({show_root: false}) %}
{{ _self.options(_context, pages.find(field.start_route), 0) }}
{% else %}
{{ _self.options(_context, pages, 0) }}
{% endif %}
</select>
</div>
{% endblock %}

View File

@@ -0,0 +1,8 @@
{% extends "forms/fields/pages/pages.html.twig" %}
{% block input %}
{% set value = admin.page.parent.rawRoute %}
{% set defaults = {show_root:true, show_all: true, show_self: false} %}
{% set field = field|merge(defaults) %}
{{ parent() }}
{% endblock %}