mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 20:11:46 +02:00
Update InputfieldSelector to support a "children…" selection that works similarly to the "parent…" selection
This commit is contained in:
@@ -504,6 +504,10 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
'label' => $this->_('Number of children'),
|
'label' => $this->_('Number of children'),
|
||||||
'sanitizer' => 'integer',
|
'sanitizer' => 'integer',
|
||||||
),
|
),
|
||||||
|
'children.' => array(
|
||||||
|
'input' => 'subfields',
|
||||||
|
'label' => $this->_x('Children',' children-with-subfield'),
|
||||||
|
),
|
||||||
'parent' => array(
|
'parent' => array(
|
||||||
'input' => 'number', // select
|
'input' => 'number', // select
|
||||||
'label' => $this->_x('Parent', 'parent-only'),
|
'label' => $this->_x('Parent', 'parent-only'),
|
||||||
@@ -1515,7 +1519,24 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
if($fieldName == 'parent' || $fieldName == 'children') {
|
if($fieldName == 'parent' || $fieldName == 'children') {
|
||||||
// for parent or children, use the existing functionality in renderSelectField
|
// for parent or children, use the existing functionality in renderSelectField
|
||||||
|
|
||||||
$fields = $this->wire('fields');
|
if($fieldName === 'children') {
|
||||||
|
/** @var Templates $templates */
|
||||||
|
$fields = array();
|
||||||
|
$initTemplates = $this->getTemplatesFromInitValue($this->initValue);
|
||||||
|
foreach($initTemplates as $template) {
|
||||||
|
if(!$template instanceof Template) {
|
||||||
|
$template = $this->wire()->templates->get($template);
|
||||||
|
}
|
||||||
|
if(!$template) continue;
|
||||||
|
foreach($template->childTemplates() as $t) {
|
||||||
|
foreach($t->fieldgroup as $field) {
|
||||||
|
$fields[$field->name] = $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$fields = $this->wire()->fields;
|
||||||
|
}
|
||||||
$out = $this->renderSelectField(array(
|
$out = $this->renderSelectField(array(
|
||||||
'name' => 'subfield',
|
'name' => 'subfield',
|
||||||
'class' => 'select-subfield',
|
'class' => 'select-subfield',
|
||||||
@@ -1525,7 +1546,7 @@ class InputfieldSelector extends Inputfield implements ConfigurableModule {
|
|||||||
'customFields' => $fields,
|
'customFields' => $fields,
|
||||||
'exclude' => array(), // prevent exclusion of 'count'
|
'exclude' => array(), // prevent exclusion of 'count'
|
||||||
'prepend' =>
|
'prepend' =>
|
||||||
"<option value='parent' class='select-subfield-default' data-name='$valueName' data-label='$valueLabel'>" .
|
"<option value='$fieldName' class='select-subfield-default' data-name='$valueName' data-label='$valueLabel'>" .
|
||||||
$valueLabel .
|
$valueLabel .
|
||||||
"</option>",
|
"</option>",
|
||||||
), $selectedValue);
|
), $selectedValue);
|
||||||
|
Reference in New Issue
Block a user