Giter VIP home page Giter VIP logo

Comments (6)

folbert avatar folbert commented on May 28, 2024

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.

zackphilipps avatar zackphilipps commented on May 28, 2024

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.

zackphilipps avatar zackphilipps commented on May 28, 2024

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.

zackphilipps avatar zackphilipps commented on May 28, 2024

Easiest solution is just to stick the brick under a tab and show/hide the tab using conditional logic. 🤷‍♂️

from fewbricks.

zackphilipps avatar zackphilipps commented on May 28, 2024

BUT if the brick were to have tabs of its own... no bueno.

from fewbricks.

folbert avatar folbert commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.