mirror of
https://github.com/joomla/joomla-cms.git
synced 2024-06-25 14:53:01 +00:00
[4.0] Subform UX (#33096)
This commit is contained in:
parent
0039f500f9
commit
d151fd31af
|
@ -0,0 +1 @@
|
|||
ALTER TABLE `#__fields` ADD COLUMN `only_use_in_subform` tinyint(1) NOT NULL DEFAULT 0;
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE "#__fields" ADD COLUMN "only_use_in_subform" smallint DEFAULT 0 NOT NULL;
|
|
@ -35,6 +35,7 @@
|
|||
label="JCATEGORY"
|
||||
extension="com_content"
|
||||
multiple="true"
|
||||
showon="only_use_in_subform:0"
|
||||
addfieldprefix="Joomla\Component\Categories\Administrator\Field"
|
||||
>
|
||||
<option value="0">JALL</option>
|
||||
|
@ -76,6 +77,17 @@
|
|||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="only_use_in_subform"
|
||||
type="radio"
|
||||
label="COM_FIELDS_FIELD_ONLY_USE_IN_SUBFORM_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="0"
|
||||
showon="type!:subform"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field
|
||||
name="default_value"
|
||||
type="textarea"
|
||||
|
|
|
@ -64,6 +64,18 @@
|
|||
>
|
||||
<option value="">JOPTION_SELECT_LANGUAGE</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="only_use_in_subform"
|
||||
type="list"
|
||||
label="COM_FIELDS_FIELDS_FILTER_ONLY_USE_IN_SUBFORM_LABEL"
|
||||
onchange="this.form.submit();"
|
||||
default=""
|
||||
>
|
||||
<option value="">COM_FIELDS_ONLY_USE_IN_SUBFORM</option>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
</fields>
|
||||
|
||||
<fields name="list">
|
||||
|
|
|
@ -11,8 +11,10 @@ namespace Joomla\Component\Fields\Administrator\Field;
|
|||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Field\ListField;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
|
||||
|
||||
/**
|
||||
|
@ -94,6 +96,11 @@ class SubfieldsField extends ListField
|
|||
}
|
||||
);
|
||||
|
||||
if (count($options) == 0)
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage(Text::_('COM_FIELDS_NO_FIELDS_TO_CREATE_SUBFORM_FIELD_WARNING'), 'warning');
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
|
|
@ -163,8 +163,20 @@ class FieldModel extends AdminModel
|
|||
// Save the assigned categories into #__fields_categories
|
||||
$db = $this->getDbo();
|
||||
$id = (int) $this->getState('field.id');
|
||||
$cats = isset($data['assigned_cat_ids']) ? (array) $data['assigned_cat_ids'] : array();
|
||||
$cats = ArrayHelper::toInteger($cats);
|
||||
|
||||
/**
|
||||
* If the field is only used in subform, set Category to None automatically so that it will only be displayed
|
||||
* as part of SubForm on add/edit item screen
|
||||
*/
|
||||
if (!empty($data['only_use_in_subform']))
|
||||
{
|
||||
$cats = [-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$cats = isset($data['assigned_cat_ids']) ? (array) $data['assigned_cat_ids'] : array();
|
||||
$cats = ArrayHelper::toInteger($cats);
|
||||
}
|
||||
|
||||
$assignedCatIds = array();
|
||||
|
||||
|
@ -559,6 +571,23 @@ class FieldModel extends AdminModel
|
|||
$form->setFieldAttribute('state', 'filter', 'unset');
|
||||
}
|
||||
|
||||
// In case we are editing a field, field type cannot be changed, so some extra handling below is needed
|
||||
if ($fieldId)
|
||||
{
|
||||
$fieldType = $form->getField('type');
|
||||
|
||||
if ($fieldType->value == 'subform')
|
||||
{
|
||||
// Only Use In subform should not be available for subform field type, so we remove it
|
||||
$form->removeField('only_use_in_subform');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Field type could not be changed, so remove showon attribute to avoid js errors
|
||||
$form->setFieldAttribute('only_use_in_subform', 'showon', '');
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class FieldsModel extends ListModel
|
|||
'state', 'a.state',
|
||||
'access', 'a.access',
|
||||
'access_level',
|
||||
'only_use_in_subform',
|
||||
'language', 'a.language',
|
||||
'ordering', 'a.ordering',
|
||||
'checked_out', 'a.checked_out',
|
||||
|
@ -147,7 +148,7 @@ class FieldsModel extends ListModel
|
|||
'DISTINCT a.id, a.title, a.name, a.checked_out, a.checked_out_time, a.note' .
|
||||
', a.state, a.access, a.created_time, a.created_user_id, a.ordering, a.language' .
|
||||
', a.fieldparams, a.params, a.type, a.default_value, a.context, a.group_id' .
|
||||
', a.label, a.description, a.required'
|
||||
', a.label, a.description, a.required, a.only_use_in_subform'
|
||||
)
|
||||
);
|
||||
$query->from('#__fields AS a');
|
||||
|
@ -348,6 +349,15 @@ class FieldsModel extends ListModel
|
|||
->bind(':groupid', $groupId, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
$onlyUseInSubForm = $this->getState('filter.only_use_in_subform');
|
||||
|
||||
if (is_numeric($onlyUseInSubForm))
|
||||
{
|
||||
$onlyUseInSubForm = (int) $onlyUseInSubForm;
|
||||
$query->where($db->quoteName('a.only_use_in_subform') . ' = :only_use_in_subform')
|
||||
->bind(':only_use_in_subform', $onlyUseInSubForm, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Filter by search in title
|
||||
$search = $this->getState('filter.search');
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ $wa->useScript('keepalive')
|
|||
<?php echo $this->form->renderField('label'); ?>
|
||||
<?php echo $this->form->renderField('description'); ?>
|
||||
<?php echo $this->form->renderField('required'); ?>
|
||||
<?php echo $this->form->renderField('only_use_in_subform'); ?>
|
||||
<?php echo $this->form->renderField('default_value'); ?>
|
||||
|
||||
<?php foreach ($this->form->getFieldsets('fieldparams') as $name => $fieldSet) : ?>
|
||||
|
|
|
@ -146,6 +146,11 @@ if ($saveOrder && !empty($this->items))
|
|||
<?php echo Text::sprintf('JGLOBAL_LIST_NAME_NOTE', $this->escape($item->name), $this->escape($item->note)); ?>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
<?php if ($item->only_use_in_subform) : ?>
|
||||
<div class="small badge bg-secondary">
|
||||
<?php echo Text::_('COM_FIELDS_FIELD_ONLY_USE_IN_SUBFORM_BADGE'); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($category) : ?>
|
||||
<div class="small">
|
||||
<?php echo Text::_('JCATEGORY') . ': '; ?>
|
||||
|
|
|
@ -46,6 +46,8 @@ COM_FIELDS_FIELD_N_ITEMS_TRASHED_1="Field trashed"
|
|||
COM_FIELDS_FIELD_N_ITEMS_UNPUBLISHED="%d fields unpublished"
|
||||
COM_FIELDS_FIELD_N_ITEMS_UNPUBLISHED_1="Field unpublished"
|
||||
COM_FIELDS_FIELD_NOTE_LABEL="Note"
|
||||
COM_FIELDS_FIELD_ONLY_USE_IN_SUBFORM_BADGE="Subform Only"
|
||||
COM_FIELDS_FIELD_ONLY_USE_IN_SUBFORM_LABEL="Only Use In Subform"
|
||||
COM_FIELDS_FIELD_PLACEHOLDER_DESC="Placeholder text which will appear inside the field as a hint to the user for the required input."
|
||||
COM_FIELDS_FIELD_PLACEHOLDER_LABEL="Placeholder"
|
||||
COM_FIELDS_FIELD_PREFIX_LABEL="Prefix"
|
||||
|
@ -59,6 +61,7 @@ COM_FIELDS_FIELD_SHOWLABEL_LABEL="Label"
|
|||
COM_FIELDS_FIELD_SUFFIX_LABEL="Suffix"
|
||||
COM_FIELDS_FIELD_TYPE_LABEL="Type"
|
||||
COM_FIELDS_FIELD_USE_GLOBAL="Use settings from Plugin"
|
||||
COM_FIELDS_FIELDS_FILTER_ONLY_USE_IN_SUBFORM_LABEL="Only Use In Subform"
|
||||
COM_FIELDS_FIELDS_FILTER_SEARCH_DESC="Search in field name, title or note. Prefix with ID: to search for a field ID. Prefix with AUTHOR: to search for a field author."
|
||||
COM_FIELDS_FIELDS_FILTER_SEARCH_LABEL="Search Fields"
|
||||
COM_FIELDS_FIELDS_TABLE_CAPTION="Table of Fields"
|
||||
|
@ -82,6 +85,8 @@ COM_FIELDS_GROUPS_FILTER_SEARCH_LABEL="Search Field Groups"
|
|||
COM_FIELDS_GROUPS_TABLE_CAPTION="Table of Field Groups"
|
||||
COM_FIELDS_MUSTCONTAIN_A_TITLE_FIELD="Field must have a title."
|
||||
COM_FIELDS_MUSTCONTAIN_A_TITLE_GROUP="Field Group must have a title."
|
||||
COM_FIELDS_NO_FIELDS_TO_CREATE_SUBFORM_FIELD_WARNING="You need to create standard fields before creating a Subform field."
|
||||
COM_FIELDS_ONLY_USE_IN_SUBFORM="Only Use In Subform"
|
||||
COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED="The <a href=\"%s\">System - Fields</a> plugin is disabled. Custom fields will not display until you enable this plugin."
|
||||
COM_FIELDS_VIEW_FIELD_ADD_TITLE="%s: New Field"
|
||||
COM_FIELDS_VIEW_FIELD_EDIT_TITLE="%s: Edit Field"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
PLG_FIELDS_SUBFORM="Fields - Subform"
|
||||
PLG_FIELDS_SUBFORM_LABEL="Subform (%s)"
|
||||
PLG_FIELDS_SUBFORM_PARAMS_CUSTOMFIELD_LABEL="Field"
|
||||
PLG_FIELDS_SUBFORM_PARAMS_MAX_ROWS_LABEL="Maximum Rows"
|
||||
PLG_FIELDS_SUBFORM_PARAMS_OPTIONS_LABEL="Fields"
|
||||
PLG_FIELDS_SUBFORM_PARAMS_RENDER_VALUES_LABEL="Render Values"
|
||||
PLG_FIELDS_SUBFORM_PARAMS_REPEAT_LABEL="Repeatable"
|
||||
|
|
|
@ -166,6 +166,7 @@ CREATE TABLE IF NOT EXISTS `#__fields` (
|
|||
`description` text NOT NULL,
|
||||
`state` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`required` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`only_use_in_subform` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`checked_out` int(10) unsigned,
|
||||
`checked_out_time` datetime,
|
||||
`ordering` int(11) NOT NULL DEFAULT 0,
|
||||
|
|
|
@ -174,6 +174,7 @@ CREATE TABLE IF NOT EXISTS "#__fields" (
|
|||
"description" text NOT NULL,
|
||||
"state" smallint DEFAULT 0 NOT NULL,
|
||||
"required" smallint DEFAULT 0 NOT NULL,
|
||||
"only_use_in_subform" smallint DEFAULT 0 NOT NULL,
|
||||
"checked_out" integer,
|
||||
"checked_out_time" timestamp without time zone,
|
||||
"ordering" bigint DEFAULT 0 NOT NULL,
|
||||
|
|
|
@ -18,7 +18,14 @@
|
|||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="max_rows"
|
||||
type="number"
|
||||
label="PLG_FIELDS_SUBFORM_PARAMS_MAX_ROWS_LABEL"
|
||||
default=""
|
||||
filter="integer"
|
||||
showon="repeat:1"
|
||||
/>
|
||||
<field
|
||||
name="options"
|
||||
type="subform"
|
||||
|
|
|
@ -291,6 +291,11 @@ class PlgFieldsSubform extends FieldsPlugin
|
|||
$parent_fieldset->setAttribute('hidden', 'true');
|
||||
$parent_fieldset->setAttribute('name', ($field->name . '_modal'));
|
||||
|
||||
if ($field_params->get('max_rows'))
|
||||
{
|
||||
$parent_field->setAttribute('max', $field_params->get('max_rows'));
|
||||
}
|
||||
|
||||
// If this field should be repeatable, set some attributes on the modal
|
||||
if ($field_params->get('repeat', '1') == '1')
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user