[wp-trac] [WordPress Trac] #37275: Facilitate creating controls that manipulate settings that have object values
WordPress Trac
noreply at wordpress.org
Mon Jul 4 20:39:27 UTC 2016
#37275: Facilitate creating controls that manipulate settings that have object
values
-------------------------+----------------------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Customize | Version: 3.4
Severity: normal | Keywords:
Focuses: |
-------------------------+----------------------------
While #37274 addresses the difficulty to manipulate updating settings that
have object values, the Customizer JS API also does not facilitate
creating controls that have fields which manage a setting that has a
object value.
The `MenuNameControl` provides a good example of a control that has a text
field for managing a nav menu setting's `name` property:
{{{#!js
control.nameElement = new api.Element( control.container.find( '.menu-
name-field' ) );
control.nameElement.bind(function( value ) {
var settingValue = control.setting();
if ( settingValue && settingValue.name !== value ) {
settingValue = _.clone( settingValue );
settingValue.name = value;
control.setting.set( settingValue );
}
});
control.setting.bind(function( object ) {
control.nameElement.set( object.name );
});
}}}
This works but it is tedious when scaling and makes it difficult to
extend, as can be seen in the `MenuItemControl`. There should be a more
declarative way to link a field to ''a property'' of a setting value
object. One implementation of this can be seen in the
[https://github.com/xwp/wp-customize-posts/blob/0.6.1/js/customize-
dynamic-control.js Dynamic control] as seen in the Customize Posts plugin.
While Core supports a `data-customize-setting-link` attribute in a control
template to declaratively link an input field to a setting value, the
Dynamic control Dynamic adds support for a `data-customize-setting-
property-link` attribute which will link the input field to the a
''property'' of the (default) setting. This eliminates the need for custom
JS logic to link the input elements.
See an example control which has fields which manipulate a setting value
containing a street address: https://github.com/xwp/standalone-customizer-
controls/blob/master/class-customize-address-control.php
This will facilitate extending nav menu items in the Customizer: #18584.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37275>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list