Comments (6)
If I understand correctly what you want to do, something like this is possible (writing this on my phone so I'll blame any errors on that):
$brick = new button('Button', 'button', 'uniqueId');
$brick->set_arg('name', 'value');
$brick->set_setting('name', 'value');
$this->add_brick($brick);
You can then fetch the arg-values with get_arg('name', [default_value])
and settings using the name of the variable like so: $this->setting_name
.
Was that what you were looking for?
from fewbricks.
Ah, no, sorry for my lack of clarity... What I wanted was a way to set conditional logic for a brick.
Something like:
$brick->set_setting('conditional_logic', [
// conditional logic here
]);
It would be super useful to bulk show/hide fields based on another single field's value!
from fewbricks.
I have tried a few different methods here... I was able to remove a field from a brick and change field names within a brick, but conditional logic is still giving me grief.
This is a flexible content field; I have tried this method on layout->get_setting( 'sub_fields' )
as well as field_group->get_setting( 'fields' )
.
I have also tried the full field key as fewbricks debugging shows it (201705182211h_201705182211i_201706070848a_201706071006a
), and the one that gets spit out in var_dump( $fields )
(201706071006a
). Both have the result of hiding the fields, but they don't show up with 201706071006a
being checked.
Here is the code:
# =============================================================================>
# conditional logic on brick
# =============================================================================>
$fields = $fewbricks_fg->get_setting( 'fields' );
// echo '<pre>';
// var_dump( $fields );
// echo '</pre>';
// wp_die();
foreach( $fields as $field_index => $field ) {
if( $field['name'] === 'modules_flex' ) {
// echo '<pre>';
// var_dump($field);
// echo '</pre>';
foreach( $field['layouts'] as $layout_index => $layout ) {
// echo '<pre>';
// var_dump($layout);
// echo '</pre>';
if( $layout['name'] === 'cta_app_download_override' ) {
$sub_fields = $layout['sub_fields'];
// echo '<pre>';
// var_dump($sub_fields);
// echo '</pre>';
foreach( $sub_fields as $sub_index => $sub_field ) {
// echo '<pre>';
// var_dump($sub_field);
// echo '</pre>';
if(
$sub_field['name'] !== 'cta_app_download_override_defaults' &&
$sub_field['type'] !== 'fewbricks_hidden'
) {
$sub_fields[$sub_index]['name'] = str_replace( 'cta_app_download_override_', '', $field['name'] );
$sub_fields[$sub_index]['conditional_logic'] = [
[
[
'field' => '201706071006a',
'operator' => '==',
'value' => '1'
]
]
];
}
}
$fields[$field_index]['layouts'][$layout_index]['sub_fields'] = $sub_fields;
}
}
}
}
$fewbricks_fg->set_setting( 'fields', $fields );
$fields = $fewbricks_fg->get_setting( 'fields' );
// echo '<pre>';
// var_dump( $fields );
// echo '</pre>';
// wp_die();
Any ideas?
from fewbricks.
Easiest solution is just to stick the brick under a tab and show/hide the tab using conditional logic.
from fewbricks.
BUT if the brick were to have tabs of its own... no bueno.
from fewbricks.
Blast from the past! I wont be adding any non-essential new functionality to Fewbricks1 since Fewbricks2 is in the works. But I will take this feature in to consideration in Fewbricks2. Thanks for the idea.
from fewbricks.
Related Issues (20)
- Preferred/better approach to registering field groups HOT 3
- Add common_field_groups
- Fewbricks 2 - ACFs register fields via PHP funcs HOT 3
- Fewbricks2 will come with major breaking changes HOT 2
- Don't hide any WP core meta boxes by default HOT 1
- Create settings specific functions for each field class HOT 1
- Deal with hide_on_screen settings for field groups
- Should Fewbricks2 implement a fluent interface? HOT 1
- Add helper function for checking if a field group has any fields with data or not HOT 2
- Add ability to add "common fields" and "common field groups" on field groups HOT 1
- Add nicer way to set display rules for field groups HOT 1
- Add nicer way to set conditional logic on fields HOT 1
- Add ability to remove fields from field groups HOT 1
- Move manual to https://fewbricksdocs.readme.io? HOT 2
- Add support for Accordion layout HOT 1
- Testing performance on PHP export HOT 1
- Improve associativeArrayToElementAttributesString HOT 1
- Is v2 taking into account new developments over at ACF concerning Gutenberg? HOT 4
- Remove fluent/chaining HOT 1
- Do we need to require the project init file? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fewbricks.